I am quite new to python. One of the problems I've been having is using sys.stdin.readline(). I've written the code out like this con = sys.stdin.readline(). After doing this I put a if statement to look at that new data. After doing this no matter what I type the output is the exact same. Here is the code that I am using:
import sys
print('Nice and quick what\'s your name?')
name = sys.stdin.readline()
print('What a great name!')
def moon_weight(weight, gain):
for year in range(1,16):
weight = weight + gain
moon = weight * 0.165
if year == 15:
print()
print('Year %s: Your weight on the moon is %s' % (year, moon))
print()
print('That\'s the end of this program for you, %s' % name)
print('Have a nice day bye!')
else:
print()
print('Year %s: Your weight on the moon is %s' % (year, moon))
print()
print('Press enter to see the next year...')
print('If you would not like to see the next year type no')
nex = sys.stdin.readline()
if nex == 'no':
print()
print('Ok, ending program now.')
print('Ending...')
break
moon_weight(55,1)
When I run the code and type no, the code continues on like I didn't write anything.
sys.stdin.readline()to get a name from the user, useinput('What is your name')for example, the same goes for thenexvariable.