Python Forum
beginner and need help with python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: beginner and need help with python (/thread-21773.html)

Pages: 1 2


RE: beginner and need help with python - Tjay - Oct-14-2019

I thought line 11 will stop the endless beer as in if the number entered is less than 1 then no beer will be served. I might be wrong but thats what the purpose was for that else clause.


RE: beginner and need help with python - jefsummers - Oct-15-2019

But if i starts at 10, it never changes, so it's beer forever. Somewhere in the loop you need to decrement i


RE: beginner and need help with python - DZ_Galaxy - Oct-15-2019

you can specify a condition only with if and elif
if i == 6:
   print("we have 6 juice")
elif i == 0:
   print("we have no juice")
elif i == 1 or i == 2:
   print("you have 1 or 2 juice")
else:
   print("we have enough of juice")
The elif statement allows you to check multiple expressions.
An else statement contains the block of code that executes if and elif conditional expression in the if statement resolves to 0 or a FALSE value.


RE: beginner and need help with python - Aurthor_King_of_the_Brittons - Oct-18-2019

Here is a decent example of how to increment and decrement in Python, specifically the augmented assignment operators section toward the end the page.

Increment and decrement