Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 PointsPython - HELP PLEASE
So I'm trying to make a python script that accepts user inputs and then show those inputs in a user-friendly CLI(text-based). I wrote this script but because I have not been coding in python for a long time, I forgot a lot of stuff. And just recently I've been trying to get back to using python.
=====I'm Sublime Text to code my python, and then I run the code in CMD.===== The problem that I'm having is whenever I try to use the second option(2 - Show data), the CMD would just close and not display anything. Can somebody check over my code and see if I have errors there. Thanks.
from os import system, name
from time import sleep
def clear():
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
first = 1;
second = 2;
def logs(online, ftime, stime, called, locser, phnumber, genclient, nameofclient):
print("PLAYER ONLINE: " + online + '\n' +
"TIME OF SERVICE: " + ftime + ":" + stime + '\n' +
"DID THEY CALL: " + called + '\n' +
"LOCATION OF SERVICE: " + locser + '\n' +
"PHONE NUMBER: " + phnumber + '\n' +
"GENDER OF CLIENT: " + genclient + '\n' +
"NAME OF CLIENT: " + nameofclient)
while True:
print("Hello")
print("1 - Add data.")
print("2 - Show data.")
options = int(input("Choose an option: > "))
if options == first:
playerStatus = int(input("How many PLAYERS are online? > "))
timeFIG = int(input("What are the first digits before : ? > "))
timeSIG = int(input("What are the second digits after : ? > "))
call = input("Did they call? > ")
locationS = input("Where did the service took place? > ")
phoneNumber = int(input("What was the phone number of the client? > "))
genderClient = input("What was the gender of the client? > ")
nameClient = input("What was the name of the client? > ")
clear()
elif options == second:
logs(playerStatus, timeFIG, timeSIG, call, locationS, phoneNumber, genderClient, nameClient)
else:
clear()
print("Sorry, I did not catch that!")
break;
input("Press 'ENTER' to exit")
1 Answer
KRIS NIKOLAISEN
54,974 PointsYou are getting a type error in your logs function for concatenating an integer with a string. You could convert back:
def logs(online, ftime, stime, called, locser, phnumber, genclient, nameofclient):
print("PLAYER ONLINE: " + str(online) + '\n' +
"TIME OF SERVICE: " + str(ftime) + ":" + str(stime) + '\n' +
"DID THEY CALL: " + called + '\n' +
"LOCATION OF SERVICE: " + locser + '\n' +
"PHONE NUMBER: " + str(phnumber) + '\n' +
"GENDER OF CLIENT: " + genclient + '\n' +
"NAME OF CLIENT: " + nameofclient)
or not convert to int in the first place
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 Pointsygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 PointsYou sir, you are a genius. Thank you so much!!! <3