0
Multiple str input in while loop
Edit: It's done. I'm throwing a coin 2 times. Everytime I throw it, I write the result into program, I write h for head or t for tail. In the end, the program outputs the result like Tail Tail Help me write the simplest program for it, then I'll learn from it. (I'm doing some other exercise (I DON'T WANNA HEAR ABOUT THOSE RESULTS!), I think I have worked out most of it, but I have no idea how to tell the program to input something more than once if it's not a number. I should probably use "while" and <=2 somewhere, but my input isn't number, so that doesn't work.) Thanks in advance and please don't give me any other clues.
5 odpowiedzi
+ 3
One way you could do it would be to just create a variable and decrement it:
ThrowsRemaining = 2
while ThrowsRemaining > 0:
ThrowResult = input("Please enter your flipped coin result")
if ThrowResult == "t": print("Tail")
if ThrowResult == "h": print("Head")
ThrowsRemaining -= 1
Another way you could do it would be:
FirstThrowResult = input("Please enter your first flipped coin result")
SecondThrowResult = input("Please enter your second flipped coin result")
if FirstThrowResult == "t": print("Tail")
else: print("Head")
if SecondThrowResult == "t": print("Tail")
else: print("Head")
Personally i'd recommend the first option but you can use whichever you'd like to. If you need any more clarification, please ask me! :3
+ 2
Here is my logic written in python on tossing coin twice. If it is helpful to you i'm glad
https://code.sololearn.com/c2Ed4AG1sHpx
+ 1
You can use a list with names. Then generate a random number, which can be used for calling an index of the list.