2

I'm working with a larger program, but what I'm really struggling with is printing the result of simple math expressions. It doesn't seem necessary that I have to assign them to a variable. I have tried a few combinations of print / int / str.

I've looked at the following questions:

I've also done several searches.

list_options = ("hammer", "rope", "blanket", "sunglasses")
print (list_options)
print()
r1 = len(list_options)
r2 = (random.randint(1, r1) +1)

print(r1)
print(r2)
print()
print ("Python range is 1 to " + r2 + "Technically range is 1 to " )
print(int(r2-1))
Andreas
  • 2,455
  • 10
  • 21
  • 24

1 Answers1

0

Python 3.5:

print('1 + 1 = %d' % (1 + 1))
print('1 + 1 = {sum}'.format(sum=(1+1)))

Python 3.6-3.7:

print(f'1 + 1 = {1 + 1}')

Python 3.8:

f'{1 + 1=}'
Cory Nezin
  • 1,551
  • 10
  • 22