#The program is as below.
このプログラムでは、2回の試行で2回の宝くじ番号を推測できます。 ユーザーがi番号を正しく推測すると、ユーザーは100ドルとなり、もう1回チャンスが得られます。 2度目のチャンスでユーザーがもう一度1つの数字を推測すると、ユーザーは何も取得しません。いくつかの出力を取り除く
import random
guessed=False
attempts=2
while attempts > 0 and not guessed:
lottery1= random.randint(0, 99)
lottery2= random.randint(45,109)
guess1 = int(input("Enter your first lottery pick : "))
guess2 = int(input("Enter your second lottery pick : "))
print("The lottery numbers are", lottery1, ',', lottery2)
if guess2==lottery2 or guess1==lottery1:
print("You recieve $100!, and a chance to play again")
attempts-=1
if (guess1 == lottery1 and guess2 == lottery2):
guessed=True
print("You got both numbers correct: you win $3,000")
else:
print("Sorry, no match")
出力は以下の通りです:
Enter your first lottery pick : 35
Enter your second lottery pick : 45
The lottery numbers are 35 , 78
You recieve $100!, and a chance to play again
Sorry, no match
Enter your first lottery pick : 35
Enter your second lottery pick : 45
The lottery numbers are 35 , 45
You recieve $100!, and a chance to play again
You got both numbers correct: you win $3,000
Sorry, no match
私はライン「あなたは$ 100受け取る!と再びプレーするチャンス」ユーザーが正しくで両方の数値を推測する場合を取り除きたいです2番目の試行ユーザーが正しい番号を推測する場合。私は意味があることを願っています。
if(guess1 == lottery1とguess2 == lottery2)の後の 'elif'文の' guess2 == lottery2 or guess1 == lottery1'を移動しようとします。 –
Thatnks Vitalii。ユーザーが両方の数字を推測する場合には、「あなたは100ドルを受け取る!そしてもう一度遊ぶチャンス」を取り除く。もう一度推測が間違っていれば、 "あなたは100ドルを受け取る!そしてもう一度遊ぶチャンス"という行を取り除かない。私は本当にあなたの助けに感謝します! –