[Tutor] File reading-(encoding problems)
Here is my code..try: data=open('info.txt') for each_line in data: try: (role,line_spoken)=each_line.split(':',1) print(role,end='') print(' said: ',end='') print(line_spoken,end='') except ValueError: print(each_line) data.close() except IOError: print("File is missing")The actual output is Man said: Is this the right room for an argument? Other Man said: I've told you once. Man said: No you haven't! Other Man said: Yes I have.The characters "" got added to the contents of my file in the beginning. Later identified it as a encoding problem. I cleared the problem by adding the encoding arguments when opening the file( data=open('info.txt',encoding='utf-8-sig')).Now my question is each time do I have to make this change or is there away to make this encoding a default one? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Difference between rounding off and typecasting to int
Hii everyone, Today i was just solving a problem in hacker-rank. A simple one to calculate the tip and tax for the meal. The resultant answer should be rounded off. I first wrote the code as below: m=float(input()) x=int(input()) t=int(input()) tip=(m*x)/100 tax=(m*t)/100 total=m+tip+tax print("The final price of the meal is $",end='') print(int(total),end='') print('.') It passed three test-cases but the last test continued to fail. Then i came to know that the problem was with rounding off. Then i edited my code to the following: m=float(input()) x=int(input()) t=int(input()) tip=(m*x)/100 tax=(m*t)/100 total=m+tip+tax print("The final price of the meal is $",end='') print(round(total),end='') print('.')Finally all test-cases passed. But I can't get to understand what round() did int() cant't do to the variable total. Can anyone pinpoint the change. Thank you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor