mercredi 7 octobre 2015

Python - How to display answer's in a table list at the end of a program?

I'm in my first intro computer science class and I haven't had any other experience with coding so, bear with me. I have an assignment which requires the user to input a number ( >100), an operation (+, -, *). At the end of the program it takes the two and they are used in conjunction with an ascending table of numbers from 1 to 10. The only issue i'm having is figuring out how to get it to show the answer after the '='.

If I could get some help, that would be great. I've literally spent a couple of hours trying to figure out this little thing and am just stumped.

 # User inputs a #
num1 = int(input("Enter a numuber of 1 or greater: "))
while (num1 < 1):
     num1 = int(input("Error! Number too small, try again!: "))

if (num1 >= 1):
     print("Correct!\n")     

# Program shows a list up to the value entered by the user
print("Counting from 0 to", str(num1) + ": ")

for i in range(0, num1 + 1, 1):
     print(i, end = "   ")

print()


# User chooses which math operation to use
usrIp = input("\nChoose a math operation (+, -, *): ")

while (usrIp != '+') and (usrIp != '-') and (usrIp != '*'):
     usrIp = input("\nError! Try again!:")


# User submitted value is added to a number increasing by 1 for each line


print("\nTable for", num1, "using", usrIp, ":")
if (usrIp == '+') or (usrIp == '-') or (usrIp == '*'):
     for i in range(1, 11, 1):
               if (usrIp == '+'):
                    print(num1, usrIp, i, '=')
               if (usrIp == '*'):
                    print(num1, usrIp, i, '=')
               if (usrIp == '-'):
                    print(num1, usrIp, i, '=')        

Aucun commentaire:

Enregistrer un commentaire