Hello!
I know that there are many code-solutions to find with google, when you type in the name of this common exercise, but many of them had another goal for their little program.
The instruction/goals for my little exercise are exactly these one:
https://gyazo.com/d0215749fe36959036bf4ed8e0c1496f
My Code so far:
My output:
I have tried already to add and else-statement , following by 'break', but it did not work.
So I do assume that my code is already at its beginning wrong regards to what it shall acchieve (given the exercise-instruction in the linked screenshot).
Can anyone please help out with some infos and explanations?
Regards,
Placebo
Update:
I think I have solved it myelf?
Maybe I just got lucky that it seems to run now, but there might be still some fundamental mistake.
As for improving the program:
For example, I when the User types anything, unless exactly 'No', the programm will treat the answer as 'Yes' and loop again.
I would like to print the program something like "Please answer only by using 'Yes' or 'No'. Try again!".
The only opportunity which comes in mind is with an elif-statement in between of the If-and-else-statements.
But this seems not possible, since need to somehow still end with 'No' and the 'else:break'.
Quick offtopic question:
Regards to commonly used python-coding-style, I do wonder which quotationmarks are more used?
The double ones " or the single ones '
?
I know that there are many code-solutions to find with google, when you type in the name of this common exercise, but many of them had another goal for their little program.
The instruction/goals for my little exercise are exactly these one:
https://gyazo.com/d0215749fe36959036bf4ed8e0c1496f
My Code so far:
import random print(random.randint(1, 6)) while True: print("Do you want to roll the dice again? Type Yes or No?") answer = input() if answer != 'No': print(random.randint(1, 6))
My output:
Output:Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
RESTART: C:/Users/kr-ga/Desktop/Programming/Python/PRAXIS/small Projects/roll the dice simulation/Roll the dice.py
2
Do you want to roll the dice again? Type Yes or No?
Yes
5
Do you want to roll the dice again? Type Yes or No?
No
Do you want to roll the dice again? Type Yes or No?
Basically, the program does not break after 'No' was typed in, so that I must assume , that something is missing or more likely that before my variables are wrongly placed and/or defined?I have tried already to add and else-statement , following by 'break', but it did not work.
So I do assume that my code is already at its beginning wrong regards to what it shall acchieve (given the exercise-instruction in the linked screenshot).
Can anyone please help out with some infos and explanations?
Regards,
Placebo
Update:
I think I have solved it myelf?
import random print(random.randint(1, 6)) while True: print("Do you want to roll the dice again? Type Yes or No?") answer = input() if answer != 'No': print(random.randint(1, 6)) else: print("Thank you for playing and see you next time!") breakI still would like to not delete my previous post, since I want to show my struggles and at the same time ask, if my code is really correct now according to the instructions and/or if you would make something different or improve something?
Maybe I just got lucky that it seems to run now, but there might be still some fundamental mistake.
As for improving the program:
For example, I when the User types anything, unless exactly 'No', the programm will treat the answer as 'Yes' and loop again.
I would like to print the program something like "Please answer only by using 'Yes' or 'No'. Try again!".
The only opportunity which comes in mind is with an elif-statement in between of the If-and-else-statements.
But this seems not possible, since need to somehow still end with 'No' and the 'else:break'.
Quick offtopic question:
Regards to commonly used python-coding-style, I do wonder which quotationmarks are more used?
The double ones " or the single ones '
?