-3

The assignment is to write a program that spits out an odd number, a number, and then does basic arithmetic on those numbers. I've gotten it to spit out outputs fine, but I cannot seem to find a way to have the generated numbers be part of the equation. Here is the code I have:

odd = int(input("Please enter an odd number from 1 to 99: "))
print(int(odd))
num = int(input("Please enter a number from 1 to 200: "))
print(int(num))
print('odd + num =',odd+num)
print('odd - num =',odd-num)
print('odd * num=',odd*num)
print('odd / num =',odd/num)
print('odd + num =',num+odd)
print('odd - num =',num-odd)
print('odd * num =',num*odd)
print('odd / num =',num/odd)

I need the 'odd / num =' section to be replaced with the numbers generated, but I'm unsure as to how to do that and my textbook says nothing about it.

Any help would really be appreciated.

  • `print( odd, "-", num,"=",odd-num)` or `print(f"{odd}-{num}={odd-num}")` or `print('{}-{}={}'.format(odd,num,odd-num))` or the outdated % formatting one... based back in pre-python-3 – Patrick Artner May 27 '18 at 16:29
  • 1
    You are even printing `odd` and `num`, so you had the solution before your eyes... `print(odd, '+', num, '=', odd+num)` or `print("%d + %d = %d" % (odd, num, odd+num,))` or `print("{} + {} = {}".format(odd, num, odd+num)` – wiesion May 27 '18 at 16:30
  • https://docs.python.org/3/library/string.html#formatspec – Patrick Artner May 27 '18 at 16:30

1 Answers1

0

you may want to do something like this:

print('{} + {} = {}'.format(odd, num, odd+num))
print('{} / {} = {}'.format(odd, num, odd/num))

and so on for the other operations.

GJCode
  • 1,959
  • 3
  • 13
  • 30