I used sys.stdin.readline() and input() in the same code. Worked both times. Below are the codes:

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')

Second code:

#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') 

But when I used sys.stdin.readline in the following code, it didn't work. Instead input() worked. Could someone please explain why sys.stdin.readline worked in the first code but not in this one?

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!')

0 Answers