-1
所以我做了這個,它的工作原理,但我有點挑剔,所以我希望它工作100%。這是代碼如何獲得一個變量,然後在Python中沒有空格的字符串
import random
input_1 = str(input("Do you want to roll a dice? Enter y for yes anything else for no. "))
if input_1 == "y":
dicesides = int(input("How many sides do you want your dice to have? "))
diceroll = random.randint(1, dicesides)
print("The dice rolled a",diceroll ".")
input_2 = str(input("Do you want to roll the dice again? Same keys. "))
while input_2 == "y":
print(random.randint(1, dicesides))
input_2 = str(input("Do you want to roll the dice again? Same keys. "))
else:
print("Okay, goodbye now.")
else:
print("Okay, goodbye now.")
當代碼運行時,它告訴我它「滾動」的數字,但它在數字後面留出空格。我不想要這種行爲。 當我發現我將如何改變第二個+骰子到它。
想通了,謝謝!
'打印(「骰子滾了」,diceroll「」)'是無效的語法。我認爲你想'印刷(「骰子滾動{}。」。格式(diceroll))'' –