Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

does anyone know how to make it print a sentence with persons name in it

yomicroyeewww
yomicroyeewww

i want to make it orint a persons name with a sentence in it

2 years ago

Voters

Comments

TopNew
4
Coder100
Coder100

Easy! There are many ways to do this.

1. fstrings

import time print('welcome young fellow replers how are you guys today?') name = input() print(name) time.sleep(1) print(f'it is nice to meet you {name}.')

2. addition

import time print('welcome young fellow replers how are you guys today?') name = input() print(name) time.sleep(1) print(f'it is nice to meet you '+name+'.')

3. Using extra args

import time print('welcome young fellow replers how are you guys today?') name = input() print(name) time.sleep(1) print(f'it is nice to meet you ', name, '.', sep="")

4. String interpolation

Use %s to insert a string, and %d to insert a number.

import time print('welcome young fellow replers how are you guys today?') name = input() print(name) time.sleep(1) print(f'it is nice to meet you %s.' % (name))

5. .format

import time print('welcome young fellow replers how are you guys today?') name = input() print(name) time.sleep(1) print(f'it is nice to meet you {}.'.format(name))
2 years ago
6
RYANTADIPARTHI
RYANTADIPARTHI

Solution

There are multiple ways to do it. here are some of them:

  • 1st one is the normal print with a ,
import time print('welcome young fellow replers how are you guys today?') name = input() print('ok', name) time.sleep(1) print('it is nice to meet you.')
  • 2nd way is formatting it:
import time print('welcome young fellow replers how are you guys today?') name = input() print("nice {}".format(name)) time.sleep(1) print('it is nice to meet you.')

IT can be used in multiple variables

import time print('welcome young fellow replers how are you guys today?') name = input() print("nice {}, this is cool {}".format(name, name)) time.sleep(1) print('it is nice to meet you.')
  • 3rd, f This is in more advanced versions of python, and is advanced of format.
import time print('welcome young fellow replers how are you guys today?') name = input() print(f"Cool {name}") time.sleep(1) print('it is nice to meet you.')

You just have to use a {} and put f before the string

  • 4th is the %s
import time print('welcome young fellow replers how are you guys today?') name = input() print("nice %s", %(name)) time.sleep(1) print('it is nice to meet you.')
  • and the + for this, put spaces, to look good
import time print('welcome young fellow replers how are you guys today?') name = input() print("cool " + name) time.sleep(1) print('it is nice to meet you.')

I put an extra space before it, so it would not be concatenated close together.


Well that's it. You can use either of them, but the most easiest way is just a ,. It's more viable. But it's your choice. any of them work.

2 years ago
1

I am assuming what you mean to ask is: when we take the name from the user using input statement, how can we print it back. Here's how:


name = input("What is your name?")
print("Hello " + name)


Output:
Hello (name of the person)

Please mark this as the answer if this is what you were looking for! Thanks!

2 years ago
2
Bookie0
Bookie0

@dhruvkumarrajan
add code blocks and syntax highlighting with the backslashes (`):

# your code here name = input("What is your name?") print("Hello " + name) # wow colors!

Screen Shot 2020-12-01 at 9.19.17 AM

2 years ago
1
Coder100
Coder100

no asking for marking as correct answer

@dhruvkumarrajan

2 years ago
1

@Coder100

oops... Sorry

2 years ago
1
Coder100
Coder100

no problem, now you know!

@dhruvkumarrajan

2 years ago
1
JBloves27
JBloves27

I think it would be better if you were more descriptive, but if you mean f strings, here it is:

# Here it is: name = input("what is your name?") print(f"Hello {name}!") # Output: What is your name? input name here. # Output: Hello name # This works, or you can do this:
# This works as well: name = input("What is your name?") print("Hello",name,"!") # Output is same # Another way:
name = input("what is your name?") print("Hello"+name+"!") # output is same

Last one:

name = input("what is your name?") print("Hello %s!" % name) # output is same

I hope this helped!

2 years ago
1
Wumi4
Wumi4

You can use the + operator.

# Here's an example print("Hi" + "user!") # Output: Hi user!
2 years ago
1

@Wumi4

I think he means with input from the user.

2 years ago
1
Wumi4
Wumi4

@dhruvkumarrajan
Then just replace the string with the input value!

name = input("Name?") print("Hello" + name)
2 years ago
Load more