我在同一代码中使用了sys.stdin.readline()和input()。两次都工作。以下是代码:
import sys
print('how much was your meal')
price = int(input())
print('how much would you like to tip in percentage')
tip = int(input())
tipamount = price * (tip/100)
print('your tip amount is %s' %tipamount + 'dollars')
第二个代码:
#import sys
#price = int(sys.stdin.readline())
#print('how much would you like to tip in percentage')
#tip = int(sys.stdin.readline())
#tipamount = price * (tip/100)
#print('your tip amount is %s' %tipamount + 'dollars')
但是当我在下面的代码中使用sys.stdin.readline时,它不起作用。相反,input()起作用了。有人可以解释一下sys.stdin.readline为什么在第一个代码中起作用而在这个代码中不起作用吗?
import sys
print('are you looking to study digital media in australia?')
answer = str(sys.stdin.read())
if answer == 'yes':
print('Deakin University has one of the best Digital Science Program!')