小编Joe*_*oey的帖子

在另一个函数中调用函数,导致由于parantheses中的参数而导致错误

碰巧我正在使用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)

python function

3
推荐指数
1
解决办法
48
查看次数

在while循环中的三个if-cases中的一个似乎不起作用,而另外两个呢?

我正在尝试用Java编写一个小程序,让用户输入四个字符串(用户名,电子邮件,密码,密码).

该程序应该检查这些字符串是否满足while循环中的某些条件,这要求用户输入上述字符串,直到它们满足这些条件.

该程序编译,前两个if案例似乎工作正常.只有两个密码(passwordpasscheck)之间的比较似乎是错误的.即使我两次输入相同的字符串,它们也没有通过比较,我不知道为什么会这样.

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)

java if-statement while-loop

1
推荐指数
1
解决办法
37
查看次数

标签 统计

function ×1

if-statement ×1

java ×1

python ×1

while-loop ×1