本帖最後由 郭詩瑜 於 2022-4-21 14:04 編輯
猜樂透- def gng(how, many):
- score = 0
- times = 0
- number = 0
- guess_list = []
- print("Guess number Game 1 - 49")
- while (times < how):
- while (number < many):
- print(f"Number {number+1}")
- y = int(input("Guess Number 1 - 49: "))
- number += 1
- guess_list.append(y)
- if (0 >= y <= 49):
- print("Please Do Not Enter Unacceptable number")
- number -= 1
- guess_list.pop()
- z = list(range(1,49))
- from random import shuffle
- shuffle(z), shuffle(z), shuffle(z), shuffle(z), shuffle(z)
- f = z[0:many]
- if (len(set(f) & set(guess_list)) > 0):
- final = set(f) & set(guess_list)
- final = list(final)
- final.sort()
- f.sort()
- print(f"[{len(final)}] Guess Is Correct, Correct Number is {final} Correct list is {f}")
- score += len(final)
- times+=1
- elif (len(set(f) & set(guess_list)) <= 0):
- print(f"All Wrong, The Correct Answer is {f}")
- times+=1
- guess_list.sort()
- print(f"Your Guess is {guess_list}")
- print(f"You Guess Total {score} out of {times * number} Number Correctly")
- return " "
- print(
- gng(
- how=int(input("How Many Times You Want To Play? : ")
- ),
- many=int(input("How Many Number You want to Guess? :")
- )
- )
- )
- play = int(input("Do you want to play again? 1 = Yes, 2 = No:"))
- if (play == 1):
- print()
- print(
- gng(
- how=int(input("How Many Times You Want To Play? : ")
- ),
- many=int(input("How Many Number You want to Guess? :")
- )
- )
- )
- elif (play == 2):
- print("Thank you for playing")
- else:
- print("Please Do Not Enter Unacceptable number")
複製代碼 |