weird error on my code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: weird error on my code (/thread-17245.html) |
weird error on my code - JTNA - Apr-03-2019 I made this code to add random numbers to an array and print the sums, all of that works except the code engine im using requires me to add "Total is:" to the sum of the random numbers, but i get an error when trying to do this, i did this o many other occasions and this doesnt work for some reason. the error is :
def test(): import random stuff = 0 num = int(input("How many values to add to the array: ")) for x in range(num): array.append(random.randint(10,99)) stuff = sum(array) print (array) print ("Total:" + stuff) RE: weird error on my code - Larz60+ - Apr-03-2019 which version of python are you using? if 3.6 or newer: import random def test(): stuff = 0 array = [] num = int(input("How many values to add to the array: ")) for x in range(num): array.append(random.randint(10,99)) print (array) stuff = sum(array) # If using python 3.6 or newer print (f"Total: {stuff}") # otherwise use: # print (f"Total: {stuff}.format()" test() |