最后输出应该是 10,而不是 30
var
k,i:integer;
begin
readln(i);
k:=0;
for i:= 10 to 99 do begin
if (i mod 3=0) then k:=k+1; end; write(k)
end.
# Hangman Game
#
# The classic game of Hangman. The computer picks a random word
# and the player wrong to guess it, one letter at a time. If the player
# can't guess the word in time, the little stick figure gets hanged.
# imports
import random
# constants
HANGMAN = (
"""
------
| |
|
|
|
|
|
|
|
----------
""",
"""
------
| |
| O
|
|
|
|
|
|
----------
""",
"""
------
| |
| O
| -+-
|
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-
|
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-/
|
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-/
| |
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-/
| |
| |
| |
| |
|
----------
""",
"""
------
| |
| O
| /-+-/
| |
| |
| | |
| | |
|
----------
""")
MAX_WRONG = len(HANGMAN) - 1
WORDS = ("OVERUSED", "CLAM", "GUAM", "TAFFETA", "PYTHON")
# initialize variables
word = random.choice(WORDS) # the word to be guessed
so_far = "-" * len(word) # one dash for each letter in word to be guessed
wrong = 0 # number of wrong guesses player has made
used = [] # letters already guessed
print("Welcome to Hangman. Good luck!")
while wrong < MAX_WRONG and so_far != word:
print(HANGMAN[wrong])
print("\nYou've used the following letters:\n", used)
print("\nSo far, the word is:\n", so_far)
guess = input("\n\nEnter your guess: ")
guess = guess.upper()
while guess in used:
print("You've already guessed the letter", guess)
guess = input("Enter your guess: ")
guess = guess.upper()
used.append(guess)
if guess in word:
print("\nYes!", guess, "is in the word!")
# create a new so_far to include guess
new = ""
for i in range(len(word)):
if guess == word[i]:
new += guess
else:
new += so_far[i]
so_far = new
else:
print("\nSorry,", guess, "isn't in the word.")
wrong += 1
if wrong == MAX_WRONG:
print(HANGMAN[wrong])
print("\nYou've been hanged!")
else:
print("\nYou guessed it!")
print("\nThe word was", word)
input("\n\nPress the enter key to exit.")
请帮忙,解释一下 for 循环的本质,用人类语言写下这里发生的事情:
used.append(guess)
if guess in word:
print("\nYes!", guess, "is in the word!")
# create a new so_far to include guess
new = ""
for i in range(len(word)):
if guess == word[i]:
new += guess
else:
new += so_far[i]
so_far = new
# High Scores 2.0
# Demonstrates nested sequences
scores = []
choice = None
while choice != "0":
print(
"""
High Scores 2.0
0 - Quit
1 - List Scores
2 - Add a Score
"""
)
choice = input("Choice: ")
print()
# exit
if choice == "0":
print("Good-bye.")
# display high-score table
elif choice == "1":
print("High Scores\n")
print("NAME\tSCORE")
for entry in scores:
score, name = entry
print(name, "\t", score)
# add a score
elif choice == "2":
name = input("What is the player's name?: ")
score = int(input("What score did the player get?: "))
entry = (score, name)
scores.append(entry)
scores.sort(reverse=True)
scores = scores[:5] # keep only top 5 scores
# some unknown choice
else:
print("Sorry, but", choice, "isn't a valid choice.")
input("\n\nPress the enter key to exit.")
请帮助我,我真的不明白为什么这条线在这里:
score, name = entry
我正在试验,而不是列出字母,它给了我“N on e”的拼写
def func():
input("Введите слово и мы разберем его по-буквам: ")
word= func()
word= str(word)
for letter in word:
print(letter)
input("Press Enter")
for х in ["spam”, "eggs”, "ham”]:
...
print(x, end=’ ’)
结果:spam eggs ham
如果您可以将它们通过打印,为什么要完成所有这一切?我请求你用人类的语言解释什么以及为什么需要这样做。
在 Python 的官方网站上找到:for 循环传统上用于当您想要重复固定次数的代码块时。Python for 语句按顺序遍历序列的成员,每次都执行块。对比 for 语句和 ''while'' 循环,在每次迭代都需要检查条件或永远重复一段代码时使用
请帮助:如何制作,以便当您跳过输入数字时, input()
它不会出错,而只是重新请求输入。
编写一个程序,将传统硬币“抛”100 次,并报告出现正面的次数和反面的次数。问题是我不知道如何正确显示所有一百次“投掷”的总和,我在这里写了一些东西,告诉我我是否认为正确,并且仍然帮助我这样做)如果你能建议一个就好了有这样的谜题的网站。
coin= random.randint(1,2)
tries=1
side1=""
side2=""
while not tries == 100:
side1=int()
side2=int()
coin= random.randint(1,2)
tries = tries + 1
if coin ==1:
side1=coin+side1
elif coin ==2:
side2=coin+side2
side2=int(side2/2)
print(coin, side1, side2)