+ 1
Pythons for beginners - Problem 23,3. While loops
Hi everyone. I have a problem with 23,3 problem solving connected with “hit or miss”. My code is here, but the result is wrong. Please help me points = 100 x = 1 while x<=4: if x == 'hit': points += 10 else: x == 'miss' points -= 20 x+=1 print(points)
10 Antworten
+ 5
this is according the task description:
points = 100
x = 1 # this a counter variable for the number of inputs
while x<=4: # there have to be 4 actions to take
inp = input() # we need this input for the actions inside the loop
if inp == 'hit':# we need to compare 'inp' variable not x variable
points += 10
else:
#x == 'miss' # this is not valid
points -= 20
x+=1# increment the counter
print(points)
+ 5
Lilit
s = 100
i = 0
while (i < 4):
t = input()
if t == "hit":
s += 10
else:
s -= 20
i+=1
print(s)
+ 4
Lilit ,
this code is doing nothing at all in our case, except it overwrites the content of the last input. this does not matter, because it is not affecting the program flow or the result. but you should remove it though.
for else clause we can not have a dedicated condion. else covers everything that is not covered by if... or elif... conditions.
+ 4
Lilit supposedly there is a feature after you miss so many times in code coach solutions that triggers the Solohelper option. Then one of the current solohelper will reach out to you via DM where your code attempt was sent to as well as the link to the code coach solution.
I, myself, haven't used it but I am somewhat familiar with the feature.
+ 4
Lilit
Try and try, when say "Get help"(in the answers), touch it and ready
+ 3
You can send to the SoloHelpers for reciving help
+ 3
How can I send it?
Thanks
+ 2
Post the full description pls..
But in your code, there are some mistakes:
points = 100
x = 1 #x is an integer now, then
while x<=4:
if x == 'hit': #(1) this condition is wrong always 1=='hit' , what are you trying here and
points += 10
else:
x == 'miss' #(2)this is invalid ,and useless instruction ..
points -= 20
x+=1
print(points)
+ 2
The problem was:
https://sololearn.com/coach/1527/?ref=app
+ 2
Lothar, thank you very much.
Anyway I used inp == ‘miss’ instead of #x == ‘miss’
Isn’t it right too?