2017-06-04 50 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/ – heliotrope

回答

1

我是不是这么多,当然,你需要+运营商concatinate变量

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")