2017-06-04 4 views
0

私のコードのすべての誤りを探している、私はかなりあると思う。誰かを指摘して、 ..私の最初のpythonスクリプトを批判して助言を探して

import time 
import re 

cls=("\n" * 50) 

fname=input("Please enter your first name:: ") 
lname=input("Please enter your last name:: ") 

while True: 
    age= str (input("Please enter your age:: ")) 
    if re.search('[0-9]', age): 
     break 

while True: 

    print("Welcome to python ",fname," ",lname,", your current age is ",age, sep="", end="") 
    print(", This string should not break") 

    addageyorn=input("Would you like to add X amount of years to your age, y or n:: ") 

    if addageyorn==("y"): 
     addage=input("How many years do you want to add to your age:: ") 
     print("OK, so you want to add ",addage," years to your current age of ",age, sep="", end="") 
     exeaddage = int(age) + int(addage) 
     computed = str(exeaddage) 
     print(", In ",addage," years you will be ",computed," years old, thanks for signing in.", sep="") 
     time.sleep(5) 
     exit() 

    if addageyorn==("n"): 
     print("Thanks for signing in") 
     time.sleep(5) 
     exit() 

    elif addageyorn!=("y", "n"): 
     print("Invalid Input") 
+1

https://codereview.stackexchange.com/をconcatinateする+オペレータを必要とし、このことについてあまりわかりません – heliotrope

答えて

1

私はあなたが変数

import time 
import re 

cls=("\n" * 50) 

fname=input("Please enter your first name:: ") 
lname=input("Please enter your last name:: ") 

while True: 
    age= str (input("Please enter your age:: ")) 
    if re.search('[0-9]', age): 
     break 

while True: 

    print("Welcome to python "+fname," "+lname+", your current age is "+age) 
    print(", This string should not break") 

    addageyorn=input("Would you like to add X amount of years to your age, y or n:: ") 

    if addageyorn==("y"): 
     addage=input("How many years do you want to add to your age:: ") 
     print("OK, so you want to add "+addage+" years to your current age of "+age) 
     exeaddage = int(age) + int(addage) 
     computed = str(exeaddage) 
     print(", In "+addage+" years you will be ",computed," years old, thanks for signing in.") 
     time.sleep(5) 
     exit() 

    if addageyorn==("n"): 
     print("Thanks for signing in") 
     time.sleep(5) 
     exit() 

    elif addageyorn!=("y", "n"): 
     print("Invalid Input") 
関連する問題