LogFAQs > #956122839

LurkerFAQs, Active DB, DB1, DB2, DB3, DB4, DB5, DB6, DB7, Database 8 ( 02.18.2021-09-28-2021 ), DB9, DB10, DB11, DB12, Clear
Topic List
Page List: 1
TopicITT: Learning Python
SpiritSephiroth
07/15/21 7:34:52 PM
#83:


1337toothbrush posted...
In what way do you want it to work? I have a couple of simple modifications, shown in the image below:



First off, when you get the input from the user, set it to a singular letter case (upper or lower) so that you can make comparisons more easily (without the modification on line 13 above, a user typing "Yes" would have the program exit).

Second, you had this after the while loop:
if roll_again != "yes" or "y":
However, that is redundant since the while loop already checks that at the beginning of the loop every time. When it exits the loop, this condition will always be true.

Here is the link to the code snippet with modifications: https://www.ideone.com/agvENu

Ah that makes sense! Thanks.

SomeLikeItHoth posted...
Here's how I ran it.

import random

roll_dice = True

while roll_dice:
print("Rolling the dice...")
print("The values are...")
print(random.randint(1, 6))

roll_again = input("Roll the dice again? (yes/no) ")
if roll_again == "yes":
roll_dice = True
else:
print("Goodbye!")
roll_dice = False

Will save this too! Thanks!

---
... Copied to Clipboard!
Topic List
Page List: 1