- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我在 IDLE 已经打开的情况下运行程序时,有时需要按 Enter 才能显示文本。
我怎样才能让它消失?
代码:
import random
def var():
dice_score = 0
repeat = ""
dicesides = input("Please enter the amount of sides you want the dice to have.\n The amounts you can have are as follows: 4, 6 or 12: ")
script(dice_score, dicesides, repeat)
def script(dicescore, dicesides, repeat):
if dicesides in [4,6,12]:
dice_score = random.randrange(1, dicesides)
print(dicesides, " sided dice, score ", dice_score, "\n")
else:
print("Please Try Again. \n")
var()
repeat = str(input("Repeat? Simply put yes or no: ").lower())
if repeat == "yes":
var()
else:
quit()
var()
谢谢。
最佳答案
您必须始终尝试在函数本身中包含您的函数需要的任何用户输入变量!此外,您忘记了将 dicesides
类型转换为 int
,因为 input()
返回一个字符串。另外,IMO,函数参数非常无用,您可以在函数本身中请求它们。
我会用下面的方式来做。
from random import randrange
def script():
dicesides = int(input("Please enter the amount of sides you want the dice to have.\n The amounts you can have are as follows: 4, 6 or 12: "))
if dicesides in [4,6,12]:
dice_score = randrange(1, dicesides)
print(dicesides, " sided dice, score ", dice_score, "\n")
return True
else:
print("Please Try Again. \n")
return False
repeat = "yes"
yes = ["yes", "y", "YES", "Y"]
while repeat in yes:
if not script():
continue
repeat = input("Repeat? Simply put yes or no: ").lower()
至于主要问题 needing an extra enter
,我不明白你的意思。使用上面的代码,无论如何都不会发生这种情况。
关于Python 程序仅在我按下回车键时出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20541001/
我在一个网站上有一个非常简单的登录脚本,它只使用 1 个简单的密码,而且它可以满足我的需要。问题是,它仅在单击“登录”字样时有效。我需要它做的是在按下 Enter 键时也能工作。这是代码:
在我的应用程序中,我有一个全局搜索字段,用于过滤列表中的数据,列表将有多个列。从其他组件设置过滤器值(设置为输入值)它正在发生,但我必须在输入上触发手动键盘事件(输入键)操作。 我尝试使用 viewC
在我的应用程序中,我使用的是 Tinymce。这是我的问题。 场景一 1) 我有这样风格的段落 Paragraph with some content. 当我将光标放在段落末尾并按下回车键时,它会像这
我有一个包含多个下拉列表和一个文本字段以及一个按钮的表单... 当我单击按钮时,会调用一个 ajax 函数...然后 ajax 会调用一个从 mysql 数据库获取结果的 php 函数... 问题是我
我想写一个程序在每句话之后做一个处理。像这样: char letter; while(std::cin >> letter) { if(letter == '\n') { // her
我在某处找到了一个非常适合我的自动完成脚本,但有一件事我不知道如何更改。当您单击下拉列表中的某些内容时,它不会提交此字符串,您必须单击以选择该字符串,然后单击提交按钮或按回车键。我希望此下拉菜单自动完
我在几周前开始使用 Xamarin Studio,但找不到下一个问题的解决方案:创建了一个包含序列号的编辑文本。我想在按下 Enter 后运行一个函数。它工作正常,当我按 Enter 时,函数运行没有
在 Android 和 iOS 中,可以将 keyboard 的 enter/return 键更改为例如“Go”按钮(和其他选项)。 在顶部上,我们可以在两个系统上看到常规的“返回”按钮,这是您在 A
具体代码如下所述: ? 1
我知道如何使用事件来测试何时按下某个键,但在 C 语言中我从来不知道该怎么做。 我真正想要的是一个“KeyListener”,它监听Up、Down、Left 和Right 方向键。我需要它在 Linu
我使用回车键从 v-textarea 输入数据,结果如下 Hello\nWorld 在默认或 rawHtml 不工作的情况下在 v-data-table 中呈现此内容 {{ props.it
我是一名优秀的程序员,十分优秀!