Hello everyone I need your help.
I am running this plain code on atom
name =input("What's your name? ")
print("Nice to meet you " + name + "!")
age = input("Your age? ")
print("So, you are already " + age + " years old, " + name + "!")
it is showing me the sand time icon at the bottom and doesn't give any output.
for other commands like
name = "Nick"
print(name)
is working perfectly.
I dont know what to do please help.
ptyhon version is 3.6.9
Related
New to Python here. I've been coding a small chatbot for a while now, and when I prompt the user to enter something instead of answering with the correct response the bot just repeats the prompt. Everything before that works just fine, but it gets stuck in a loop of asking the user for an input.
print("Hello " + User_Name + """.
Tonic is a simple Python chatbot made in order to test things such as boolean logic
and variable definition.
(Also remember to speak to the bot in lowercase, without punctuation.)""")
while 1 == 1:
str1 = input("Say something: ")
#"hello" //////////////////////////////////////////
if "hello" in str1:
print("Hi " + User_Name + "! (I read this as the 'hello' greeting.");
#"hi" //////////////////////////////////////////
if "hi" in str1:
print("Hi " + User_Name + "! (I read this as the 'hi' greeting.");
#"how are you?" //////////////////////////////////////////
if "how are you" in str1:
print("good, how about you? (I read this as you asking 'how are you'.)")
mood = input("Enter Mood: ")
if "good" in mood:
print("Nice to hear " + User_Name + "! (I read this as you being in a good mood.)");
if "bad" in mood:
print("I hope you feel better soon, " + User_Name + "! (I read this as you being in a bad mood.)");
#"name length" //////////////////////////////////////////
if "name length" in str1:
print( "Your name is " + len(User_Name) + "letters long. (I read this as you asking how long your name is.");```
Your while loop does not have an exit condition. It will repeat forever since 1
is always equal to 1.
Instead, you could do while (str1 != "quit") which would stop the while loop once the user enters "quit" in the prompt.
Also, side note, you should not be using semicolons at the end of lines in Python.
print("Hello " + User_Name + """.
Tonic is a simple Python chatbot made in order to test things such as boolean logic
and variable definition.
(Also remember to speak to the bot in lowercase, without punctuation.)""")
while (str1 != "quit"): # You need an exit condition here
str1 = input("Say something: ")
#"hello" //////////////////////////////////////////
if "hello" in str1:
print("Hi " + User_Name + "! (I read this as the 'hello' greeting.")
#"hi" //////////////////////////////////////////
if "hi" in str1:
print("Hi " + User_Name + "! (I read this as the 'hi' greeting.")
#"how are you?" //////////////////////////////////////////
if "how are you" in str1:
print("good, how about you? (I read this as you asking 'how are you'.)")
mood = input("Enter Mood: ")
if "good" in mood:
print("Nice to hear " + User_Name + "! (I read this as you being in a good mood.)")
if "bad" in mood:
print("I hope you feel better soon, " + User_Name + "! (I read this as you being in a bad mood.)")
#"name length" //////////////////////////////////////////
if "name length" in str1:
print( "Your name is " + len(User_Name) + "letters long. (I read this as you asking how long your name is.")
Fix indentation
Convert output from len into string
print("Hello " + User_Name + """.
Tonic is a simple Python chatbot made in order to test things such as boolean logic
and variable definition.
(Also remember to speak to the bot in lowercase, without punctuation.)""")
while 1 == 1:
str1 = input("Say something: ")
#"hello" //////////////////////////////////////////
if "hello" in str1:
print("Hi " + User_Name + "! (I read this as the 'hello' greeting.");
#"hi" //////////////////////////////////////////
if "hi" in str1:
print("Hi " + User_Name + "! (I read this as the 'hi' greeting.");
#"how are you?" //////////////////////////////////////////
if "how are you" in str1:
print("good, how about you? (I read this as you asking 'how are you'.)")
mood = input("Enter Mood: ")
if "good" in mood:
print("Nice to hear " + User_Name + "! (I read this as you being in a good mood.)");
if "bad" in mood:
print("I hope you feel better soon, " + User_Name + "! (I read this as you being in a bad mood.)");
#"name length" //////////////////////////////////////////
if "name length" in str1:
print( "Your name is " + str(len(User_Name)) + "letters long. (I read this as you asking how long your name is.");
i just found a module which you can create a chatbot with just a handful lines of code
refer to this https://pypi.org/project/prsaw/
or
from prsaw import RandomStuff
random = RandomStuffV2()
str1 = input("message: ")
response = random.get_ai_response(str1)
print(response)
Hello I got some stuck in my code and I tried but I still don't know how to fix it. Here it's my code.
def staff_info (name):
print ("So you are " + name + ", years old. ")
name = input ("Type your name: ")
confirm_info = input ("So you have " + name + ". Confirm that? (Yes/No) ")
if confirm_info == "Yes":
print ("Okay so I have few more question for you. ")
else:
confirm_info == "No"
change_info = input ("So what do you want to change? ")
if change_info == "name":
name_change = input ("Type the name you want to change: ")
name = name.replace (name_change) #error here
...
else:
...
print ("So you are " + name + ", " + age + " years old. You have over " + result_experience1 + " with code.")
If you could explain it and give me a command to solve it, I'd appreciate it. My adventure with Python beginning last week from now. Thanks you.
Thereplace method takes two mandatory parameters:
The substring you want to replace
The new value
So, change this
name = name.replace (name_change)
to
name = name.replace(name, name_change)
More here
You can try this:
def staff_info(name):
print("So you are " + name + ", years old. ")
name = input("Type your name: ")
confirm_info = input("So you have " + name + ". Confirm that? (Yes/No) ")
if confirm_info == "Yes":
print("Okay so I have few more question for you. ")
elif confirm_info == "No":
change_info = input("So what do you want to change? ")
if change_info != name:
name_change = input("Type the name you want to change: ")
new_name = name_change.replace(name, name_change)
print("New Name = ", new_name)
else:
print("...")
I'm starting to learn Python by throwing myself in the deep end and trying a bunch of exercises.
In this particular exercise, I'm trying to make a program to ask the name and age of the user and tell the user the year they're going to turn 100.
I tried putting in a yes/no input to ask if the user's birthday has passed this year, and give the correct year they will turn 100, based on that.
I wanted to incorporate a while loop so that if the user enters an answer that isn't "yes" or "no", I ask them to answer either "yes" or "no". I also wanted to make the answer case insensitive.
print("What is your name?")
userName = input("Enter name: ")
print("Hello, " + userName + ", how old are you?")
userAge = input("Enter age: ")
print("Did you celebrate your birthday this year?")
while answer.lower() not in ('yes', 'no'):
answer = input ("Yes/No: ")
if answer.lower() == 'yes':
print ("You are " + userAge + " years old! That means you'll be turning 100 years old in the year " + str(2019 - int(userAge) + 100))
elif answer.lower() == 'no':
print ("You'll be turning " + str(int(userAge) + 1) + " this year! That means you'll be turning 100 years old in the year " + str(2019 - int(userAge) + 99))
else:
print ('Please type "Yes" or "No"')
print ("Have a good life")
You should addd the input before trying to access the answer.lower method, so it will be something like:
answer = input('Yes/No: ')
while answer.lower() not in ('yes','no'):
answer = input('Yes/No: ')
Check geckos response in the comments: just initialize answer with an empty string
I started learning python and now I stuck with this "easy" code. Where is the problem, thanks in advance!
name = input("Enter your name: ")
age = input("Enter your age: ")
print("Hello " + name + "! Your are " + age)
...in the console the strings (name + input) are red and while I´m typing, I can´t see what I´m typing. After I entered a name and press enter, I get this in my console:
Enter your name:Hello Bob! Your are
Enter your age:
Process finished with exit code 0
I'm very new to this, so please be gentle!
As a little bit of work for my Python course, I am learning to run user input code. I put together the below code but when I run it using command-B, it asks me the 'What's your name?' question, but when I type in my name and click enter, nothing happens? For info, I am using Python 3.7, and using SublimeText.
I am 100% sure this is an easy answer, but surprisingly I cannot find the answer, and I have searched a little bit on here, and generally via Google, etc.
name=input("What's your name?:")
print("Hi",name,"how do you do.")
age=input("How old are you",name,"?:")
print("Great",name,"I'm",age,"years old too.")
city=input("Which city do you come from",name,"?:")
print("What a coincidence, I am from",city,"too.")
print(name,", here is your record //")
print(name, age, city)
Thanks for any help, and if you guys have an tips for a super newbie, it would be much appreciated!
You are having some issues because you have few syntax errors. The following is your code with the corrections. There you go:
name = input("What's your name?:")
print("Hi "+ name + " how do you do.")
age = input("How old are you " + name + " ?:")
print("Great " + name + "I'm " + age + " years old too.")
city = input("Which city do you come from " + name + " ?:")
print("What a coincidence, I am from " + city + " too.")
print(name + " , here is your record //: ")
print(name + " " + age + " " + city)
Good luck with learning Python :)
a = input() //for string
b = int(input()) //for int
c = float(input()) //for float
name=input("What's your name?:")
print("Hi"+name+"how do you do.")
age=input("How old are you "+name+" ?:")
print("Great "+name," I'm ",age+" years old too.")
city=input("Which city do you come from "+name+" ?:")
print("What a coincidence, I am from "+city+" too.")
print(name+", here is your record //")
print(name+age+city)
Use + for concatenation inside print