34 AnswersNew Answer
Daniel Lopez this way EOF is recognised as end of input, also allowing you to write as many lines as you want: x = 100 try: while True: if input() == "hit": x += 10 else: x -= 20 except: print(x) NOTE: This works on SoloLearn only, normally doing so you would have an infinite input loop
According to the task, Your 'a' should start from 1. Also, you missed to print the final score. Daniel Lopez Lol I missed to notice one thing. We have to change our while loop condition. It should be while a<5 So, your code needs to be , x= 100 a=1 while a <5: y= input() if y == "hit": x+=10 elif y== "miss": x-=20 a+=1 print(x)
Daniel Lopez & Dipanshu Kubde This is how multiple inputs are handled in sololearn ide. miss (Enter) miss (Enter) hit (Enter)... https://code.sololearn.com/ciavU58GXz1D/?ref=app Btw, I think you solved this code challenge. https://www.sololearn.com/post/664632/?ref=app
Simba that’s exactly it!! but yours works and mune doesn’t. Still get the EOF on y=input()
Daniel Lopez Question unclear and the if condition will always be true and thus theres no role for an elif after that ... Pls clarify the question with sample input and output for recieving better help :)
Daniel Lopez the EOF (End Of File) exception is thrown when there is no more data to pass to input(). The "try" block checks exception raising, "except" is the block called when any exception is thrown. I used "while True" because we don't necessarily know how many lines of input the user will write, whatever the number will be we're sure that the process will ends and outputs the result when input ends.
you’re right! sorry!! the question is how to calculate the final score of a player that beguins with 100 points and takes a shot. if he misses, he looses 20 points. if he hits, he adds 10 points. example imput: miss miss hit miss expected output: 50
Try : x=100 a=0 while(a<4): y=input("hit or miss") if y=="hit ": x+=10 else : x-=20 ++a print(x) //no of iterations not mentioned in the question , considering it to be 4 from sample input 😉....
would a be the number of iterations?
if yes, then that restriction would be the one that closes the loop, right? what does ++a do? what does a=0 mean?
no, it won’t run and doesn’t recognize neither the ++a not the variables hit or miss
Daniel Lopez While Loop iterates 4 times ie from a=0 to a=3 and when "a" becomes 4 ,the loop terminates ... ++a => a=a+1 its a prefix increment operator ...You can change the while condition to suit your needs ....hope it helps
Daniel Lopez Check whether the program is properly intended ...
it does help. i managed to fix the iteration and the ++a. however, the program throws a EOF error when I put y = input (“hit” or “miss) so that the if condition recognizes the variable hit in: if y == “hit”:
x = 100 a = 0 while a < 4: y = input() if y == "hit": x += 10 else: x -= 20 a = a + 1 still won’t run 😭
You need to provide all the inputs at once in sololearn ,it is not interactive like visual Studio or any other IDE Dipanshu Kubde Lol what you saying ? Pls dont forward misleading answers ...
still gives me the EOF error in line 4 and doesn’t read: y=input ()