RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-375644

Эдуард Ван's questions

Martin Hope
Эдуард Ван
Asked: 2020-03-21 01:32:05 +0000 UTC

帮助输出 10 而不是 30 [关闭]

  • -2
关闭。这个问题需要澄清或补充细节。目前不接受回复。

想改进这个问题?通过编辑此帖子添加更多详细信息并澄清问题。

2年前关闭。

改进问题

在此处输入图像描述

最后输出应该是 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.
pascal
  • 1 个回答
  • 10 Views
Martin Hope
Эдуард Ван
Asked: 2020-03-14 18:03:50 +0000 UTC

帮我弄清楚 for 循环在这里做什么

  • 1
# 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
python
  • 2 个回答
  • 10 Views
Martin Hope
Эдуард Ван
Asked: 2020-03-13 19:25:39 +0000 UTC

保存记录的应用程序。奇怪的代码行

  • 0
# 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
python
  • 1 个回答
  • 10 Views
Martin Hope
Эдуард Ван
Asked: 2020-03-09 13:46:11 +0000 UTC

def和for,序列输出问题[关闭]

  • 0
关闭。这个问题需要具体说明。目前不接受回复。

想改进这个问题? 重新构建问题,使其只关注一个问题。

2年前关闭。

改进问题

我正在试验,而不是列出字母,它给了我“N on e”的拼写

def func():
    input("Введите слово и мы разберем его по-буквам: ")
word= func()
word= str(word)
for letter in word:
    print(letter)

input("Press Enter")
python
  • 1 个回答
  • 10 Views
Martin Hope
Эдуард Ван
Asked: 2020-03-08 17:23:42 +0000 UTC

python中的for循环,简单的问题

  • -2
for х in ["spam”, "eggs”, "ham”]:
    ...
    print(x, end=’ ’)

结果:spam eggs ham

如果您可以将它们通过打印,为什么要完成所有这一切?我请求你用人类的语言解释什么以及为什么需要这样做。

在 Python 的官方网站上找到:for 循环传统上用于当您想要重复固定次数的代码块时。Python for 语句按顺序遍历序列的成员,每次都执行块。对比 for 语句和 ''while'' 循环,在每次迭代都需要检查条件或永远重复一段代码时使用

python
  • 1 个回答
  • 10 Views
Martin Hope
Эдуард Ван
Asked: 2020-03-07 22:49:34 +0000 UTC

关于 Python 中 input() 的问题

  • 0

请帮助:如何制作,以便当您跳过输入数字时, input()它不会出错,而只是重新请求输入。

python
  • 1 个回答
  • 10 Views
Martin Hope
Эдуард Ван
Asked: 2020-03-07 20:42:24 +0000 UTC

帮助解决python问题

  • 0

编写一个程序,将传统硬币“抛”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)


python
  • 3 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5