System version :Windows 10
repeat = True
while(repeat):
str_press = input('Print \'Hello world\' if you press y , don not print \'Hello world\' if you press n\n')
if str_press=='y':
repeat = False
print('Hello world!')
elif str_press=='n':
repeat = False
print('Nothing happened.')
else:
print('Please press y or n.')
執行結果:Print 'Hello world' if you press y , don not print 'Hello world' if you press n y Hello world! # or Print 'Hello world' if you press y , don not print 'Hello world' if you press n n Nothing happened. # or Print 'Hello world' if you press y , don not print 'Hello world' if you press n h Please press y or n. Print 'Hello world' if you press y , don not print 'Hello world' if you press n
沒有留言:
張貼留言