2016-08-30 7 views
0

機能が動作しないため、コードに助けを借りてください。NumberError()ポイントは、数学クイズに答えるときに入力するとpythonコード関数が算術クイズに機能せず、パスワードが機能しない

ここ
Traceback (most recent call last): 
    File "C:/Users/Helen/Documents/Computer Science Summer Task/Helen_Summer Tasks-1_2_3.py", line 77, in <module> 
    StudentAnswer = int(input("Please answer the question: ")) 
ValueError: invalid literal for int() with base 10: 'g' 

は、私がこれまで試みられてきたものです::誤って文字が、それは誤りが来る保つようしかし、私はそれが仕事を得ることができない、「NUMBERを入力してください」と言うだろう

def NumberError(): 
    if StudentAnswer not in Turns '1,2,3,4,5,6,7,8,9,10': 
      print('Please enter a NUMBER.') 
    else: 
     return ("\nQuestion") 

また、クイズにアクセスするためのパスワードオプションは完全に機能しません。私がこれまでにしてきたことは、私が正しいことをする必要があるか、私が間違っていることを助けることができれば、私はそれを感謝します。

from tkinter import * 
import tkinter as tk 
window = tk.Tk() 


import os 

#Must Access this to continue. 


def checkPassword(): 
    password = "Starfish" 
    def enteredPassword(): 
     passwordEntry.get() 
    if password == enteredPassword: 
     confirmLabel.config(text="Access granted") 
    else: 
     confirmLabel.config(text="Access denied") 

passwordLabel = tk.Label(window, text="Password:") 
passwordEntry = tk.Entry(window, show="*") 

button = tk.Button(window, text="Enter", command=checkPassword) 
confirmLabel = tk.Label(window) 

passwordLabel.pack() 
passwordEntry.pack() 
button.pack() 
confirmLabel.pack() 

window.mainloop() 

THIS IS SO FAR CODE OF MY OVERALL PIECE:

from tkinter import * 
import tkinter as tk 
window = tk.Tk() 


import os 

#Must Access this to continue. 


def checkPassword(): 
    password = "Starfish" 
    def enteredPassword(): 
     passwordEntry.get() 
    if password == enteredPassword: 
     confirmLabel.config(text="Access granted") 
    else: 
     confirmLabel.config(text="Access denied") 

passwordLabel = tk.Label(window, text="Password:") 
passwordEntry = tk.Entry(window, show="*") 

button = tk.Button(window, text="Enter", command=checkPassword) 
confirmLabel = tk.Label(window) 

passwordLabel.pack() 
passwordEntry.pack() 
button.pack() 
confirmLabel.pack() 

window.mainloop() 

#Summer_Task1.py 
import random 
def get_Name(): 
    global Name 
    global Class 
#Inputs pupil's class 
while True: 
    Class = input ("Please select your class: A)Class 1 B)Class 2 C)Class 3 [C1/C2/C3]? : ") 

    # check if d1a is equal to one of the strings, specified in the list 
    if Class in ['C1', 'C2', 'C3']: 
     # process the input 
     print("Thank you.") 
     # if it was equal - break from the while loop 
    break 

def start_quiz(): 
    print("Welcome to the Numeracy quiz that will test your basic arithmatic skills!") 
Name = input("Please enter your first name and surname: ") 
print("Hi " + Name + "!" + " Please ANSWER the following NUMERACY QUESTIONS and then PRESS ENTER to work out whether they are RIGHT or WRONG. Please ENTER a NUMBER.") 
print("You will receive a total score at the end of the quiz.") 
def Questions(): 
    global score 
    global questionnumber 
Score = 0 
questionnumber=0 
while questionnumber<10: 
     questionnumber=questionnumber+1 
     Turns = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 
for n in Turns: 
    Number1 = random.randint(1, 10) 
    Number2 = random.randint(1, 10) 
    Number3 = random.randint(1, 3) 

    if Number3 == 1: 
     Answer = Number1 + Number2 
     Sign = " + " 
    elif Number3 == 2: 
     Answer = Number1 - Number2 
     Sign = " - " 
    elif Number3 == 3: 
     Answer = Number1 * Number2 
     Sign = " x " 
    print("\nQuestion", n, "\n", Number1, Sign, Number2) 
    StudentAnswer = int(input("Please answer the question: ")) 
    print("The correct answer is:", Answer) 
    if StudentAnswer == Answer: 
     Score = Score + 1 
     print("Well Done, that is correct!") 
    else: 
     print("Sorry that is incorrect!") 
def NumberError(): 
    if StudentAnswer not in Turns '1,2,3,4,5,6,7,8,9,10': 
      print('Please enter a NUMBER.') 
    else: 
     return ("\nQuestion") 

print("\nName:", Name) 
print("\nClass:", Class) 
print("\nScore:", Score) 

ありがとう!

答えて

1

あなたは、誰もが、私はパスワード機能を改善するために何ができるか私に言うことができる場合、私は思ったんだけど、非常にint型

i = input("Please answer the question: ") 
if(not type(i) is int): 
    print('Please enter a NUMBER.') 
+0

おかげ@Owenドイル –

+0

としてそれをキャストするのではなく、入力タイプをテストすることができ? ? –

関連する問題