2016-11-23 81 views
-3
print ('welcome, uhhh whats your name?') 
name = str(input('tell me here: ')) 
print ('thats better') 
import time 
print ('welcome,',name,'this is the forst step on your long journey...') 
time.sleep(0.5) 
print ('well no, this is just a widget app...') 
time.sleep(0.5) 
print ('so umm just enter the widget you want') 
print (' by the way this will repeat forever sooo, just kill the program when you have had enough') 
while True: 
    wid = str(input('choose from these(CAPS SENSITIVE): dice, usernamegen, ')) 
    import random 
    if wid == 'dice': 
     print ('YOU HAVE CHOSEN...') 
     print ('DICE!') 
     dice = int(input('how many would you like to roll(MAX3): ')) 
     if dice == 1: 
      print ('you rolled a',(random.randint(1,6))) 
     elif dice == 2: 
      print ('you rolled a',(random.randint(1,6))) 
      print ('you rolled a',(random.randint(1,6))) 
     elif dice == 3: 
      print ('you rolled a',(random.randint(1,6))) 
      print ('you rolled a',(random.randint(1,6))) 
      print ('you rolled a',(random.randint(1,6))) 
     else: 
      print ('next time enter an option') 
    elif wid == 'usernamegen': 
     print ('This app will generate your online username') 
     lname = input('enter your last name here ') 
     print('wait 3 seconds') 
     username = name[:1]+lname[:3]+random.randint(1,99999) 
     time.sleep(3) 
     print (username) 

這是我使用的代碼,但我得到這個錯誤類型錯誤:必須海峽,不是int

line 33, in <module> 
    username = str(name[:1]+lname[:3]+random.randint(1,99999)) 
TypeError: must be str, not int 
+0

錯誤消息說明了這一切。你只能添加一個類型。所以'name [:1]','lname [:3]','random.randint(1,99999)'必須是字符串,否則所有em都必須是整數。 –

+0

'random.randint'返回一個'int'你應該使用'str(random.randint)'來將其轉換爲'str'。 – Arman

回答

2
name[:1]+lname[:3]+str(random.randint(1,99999)) 

如上所述使用它。這應該工作。

相關問題