碰巧我正在使用Python进行编程,我正准备编写一个小石头剪刀游戏.
不幸的是,当我尝试运行我的脚本时,我收到以下错误:
file rps.py, line 53 in game
compare (move,choice)
NameError: name 'move' is not defined"
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码:
from random import randint
possibilities = ['rock', 'paper', 'scissors']
def CPU(list):
i = randint(0, len(list)-1)
move = list[i]
#print (str(move))
return move
def User():
choice = str(input('Your choice? (Rock [r], Paper[p], Scissors[s])'))
choice = choice.lower()
if choice == 'rock' or choice == 'r':
choice = 'rock'
elif choice == 'scissors' or choice =='s':
choice = 'scissors'
elif choice == 'paper' or choice == …
Run Code Online (Sandbox Code Playgroud) 我正在尝试用Java编写一个小程序,让用户输入四个字符串(用户名,电子邮件,密码,密码).
该程序应该检查这些字符串是否满足while
循环中的某些条件,这要求用户输入上述字符串,直到它们满足这些条件.
该程序编译,前两个if
案例似乎工作正常.只有两个密码(password
和passcheck
)之间的比较似乎是错误的.即使我两次输入相同的字符串,它们也没有通过比较,我不知道为什么会这样.
import java.util.Scanner;
public class Registry {
public static void main (String [] args){
Scanner scanner = new Scanner(System.in);
// Dialogue for the user to fill
System.out.println("Please enter your username (at least 5 characters)");
String username = scanner.nextLine();
System.out.println("Please enter a valid emailadress (an @ is necessary for it to pass.)");
String email = scanner.nextLine();
System.out.println("Please enter two matching passwords, so we can make sure that you entered them correctly."); …
Run Code Online (Sandbox Code Playgroud)