So the code I'm doing is this:
first_name = input("What is your first name? ")
last_name = input("What is your last name? ")
print("Hi there " + first_name + last_name)
What I want to do is make a space so when I run it it shows a space between first_name and last_name.
When I run the program, it shows:
What is your first name? px1se
What is your last name? unknown
Hi there px1seunknown
I wanna get a space between the "px1se" and the "unknown".
For your print statement, try the f-string:
print(f'Hi there {first_name} {last_name}')
Here is the documentation
Or, alternatively,
print("Hi there " + first_name + " " + last_name)
or
print("Hi there {} {}".format(first_name, last_name))
try :
print("Hi there " + first_name +" "+ last_name)
Plenty of sensible approaches offered already, but I thought it might be worth adding the old style formatting to the list.
print("Hi there %s %s"%(first_name,last_name))
Related
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
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
How to make a program which will tell the user how many letters were in their surname or first name. Here I have the code so maybe you have any adjustments to it just let me know. Thanks:)
print( len( input("what is your name? ") ) )
Unfortunately, your code is in an image. I use a screen reader so can't see the image, but I can write an example program:
#Example 1, count all characters in the user's input
fn=input("What is your first name?")
ln=input("What is your surname?")
print("Your first name has " + str(len(fn)) + " characters, and your surname has " + str(len(ln)) + " characters.")
#Example 2, count *only* ASCII letters in user's input
import string
fn=input("What is your first name?")
ln=input("What is your surname?")
fncount=0
lncount=0
for i in fn:
if i in string.ascii_letters:
fncount+=1
for i in ln:
if i in string.ascii_letters:
lncount+=1
print("Your first name has " + str(fncount) + " letters, and your surname has " + str(lncount) + " letters.")
This is what I have to do:
Write a Python program which accept the user's first and last name and print them in reverse order with a space between them. THE LETTERS OF THE FIRST AND LAST NAMES SHOULD ALSO BE IN REVERSE ORDER!!!!! For example if a person enters first name is Sam and last name is Murrow then the output should be maS worruM...
-
I can't figure out how to add the space in between firstname & lastname. This is what I have so far:
firstname = input("What is your last name?:")
lastname = input("What's your last?: ")
print (lastname) + (firstname)[::-1]
In your solution you are only reversing the firstname string. What you can do instead is build your full string including both firstname, lastname and a space between them, and then reverse the entire string.
For example:
firstname = input("What is your last name?:")
lastname = input("What is your last?")
print(firstname[::-1] + " " + lastname[::-1])
Try this:
firstname = input("What is your first name?:")
lastname = input("What's your last name?: ")
fn = firstname[::-1]
ln = lastname[::-1]
print (fn,"",ln)
Do this:
first_name = input("Enter your First Name: ")
last_name = input("Enter your Last Name: ")
print(f"{first_name[::-1].strip()} {last_name[::-1].strip()}")
This code will prompt the user to input their First and Last names separately and then store those values in first_name and last_name variables respectively so that they can be used in the print statement (or for other purposes). Also it will remove extra space from input while it will print output
Here's a different approach to solve this problem
print("Enter the name: ")
name = str(input()).split(' ')
namez = name.reverse()
for i in range(len(name)):
print(name[i][::-1], end=" ")
print("{last} {first}".format(last=lastname[::-1], first=firstname[::-1]))
first_name = input("Input your First Name : ")
last_name = input("Input your Last Name : ")
print ("Hello " + last_name + " " + first_name)
I'm fairly new to Python, and I'm working on a few things that would involve names. Something such as:
example = raw_input ("What is your name?: ")
How would I go about using this to have them answer it, and reprint their name such as:
print "Hello, {name}!"
You were very close, you already had the correct template, now you have to tell it what the {name} should be replaced by:
>>> example = "Foo"
>>> "Hello, {name}!".format(name=example)
'Hello, Foo!'
See the docs for more information on using str.format.
print "Hello, " + example + "!"
There are several ways to acomplish your goal.
As was mentioned, you could use:
name = raw_input ("What is your name?: ")
print "Hello, " + name + "!"
or,
>>> example = "Foo"
>>> "Hello, {name}!".format(name=example)
'Hello, Foo!'
You could also use,
name = raw_input("What is your name?: ")
print "Hello, %s!" % name
print raw_input('Enter name :')
For Python 3.5 users, it can work like this:
name = input("What is your name? ")
print "Hello, %s!" % (name)
That should work.
name = raw_input ("What is your name?: ")
print "Hello, " + name + "!"