Python Forum
problem a with a word question
Thread Rating:
  • 2 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem a with a word question
#1
I am stumped solving this question, does anyone have a solution? Huh
prefix = "Sir"
first = "Reginald"
last = "Poofter"
suffix = "III"
Reply
#2
What's the question?
Reply
#3
(May-25-2018, 09:25 PM)micseydel Wrote: What's the question?
Output:
The question is to use word parts to make 2 correct answers. A example is shown above.
Reply
#4
"above"?

Please take a careful look at both of your threads. We want to help. But there is a minimum contribution we need from you - not because of any arbitrary rules, but because we literally don't have enough information to do so. You need to look at your threads and consider, "Is there enough information here for someone to help me with this?"
Reply
#5
Fancy names

Use a multiple assignment to add the prefix before the given first name and the suffix after the given last name, then print the full name. The string value in first should include the prefix, and the string value in last should include the suffix.

Remember
Add spaces between the words!

prefix = "Sir"
first = "Reginald"
last = "Poofter"
suffix = "III"

1

print ("Sir Reginald Poofter III")

2

prefix = "Mr"

3

first = "Maxmilian"

4

last = "Archibaldus"

5

suffix = "Sr"

6

print ("Mr Maxilian Archibaldus Sr")

7



Expected output
Sir Reginald Poofter III
Reply
#6
(May-27-2018, 02:01 PM)baobei Wrote: Use a multiple assignment to add the prefix before the given first name and the suffix after the given last name, then print the full name. The string value in first should include the prefix, and the string value in last should include the suffix.

Remember
Add spaces between the words!

Hi!

You could use something like:

import random

print(f"These are some possible random names:\n")
for x in range (25):
    prefix = random.choice(['Sir', 'Mr', 'Dr', 'Lord', 'Captain'])
    first = random.choice(['Alexis', 'Ashley', 'Casey', 'Jordan', 'Taylor'])
    last = random.choice(['Smith', 'Jones', 'Davies', 'Evans', 'Wilson'])
    suffix = random.choice(['Sr', 'Jr', 'II', 'III', 'IV'])
    print(f"{prefix} {first} {last} {suffix}.")
and that produces random names outputs like the following one:
Output:
These are some possible random names: Captain Jordan Wilson Sr. Dr Taylor Davies III. Captain Ashley Evans Jr. Dr Ashley Davies III. Captain Ashley Wilson Jr. Dr Jordan Davies IV. Captain Alexis Evans Jr. Sir Alexis Jones II. Dr Casey Jones Jr. Dr Jordan Jones III. Dr Ashley Davies Sr. Dr Ashley Davies II. Sir Ashley Wilson Jr. Mr Jordan Wilson Sr. Captain Jordan Davies Sr. Captain Taylor Jones Jr. Captain Casey Smith IV. Dr Casey Evans Sr. Lord Ashley Evans II. Mr Ashley Davies IV. Sir Alexis Smith Jr. Captain Taylor Wilson III. Mr Ashley Davies II. Captain Taylor Smith Sr. Dr Taylor Davies IV. >>>
All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Big Grin question about simple algorithm to my problem jamie_01 1 1,669 Oct-04-2021, 11:55 AM
Last Post: deanhystad
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,488 Aug-12-2021, 04:25 PM
Last Post: palladium
  General list size question to solve problem Milfredo 3 2,348 Sep-27-2020, 08:42 AM
Last Post: Milfredo
  Question in python function problem saratha 1 1,454 Jul-08-2020, 04:56 PM
Last Post: jefsummers
  Python Speech recognition, word by word AceScottie 6 15,989 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  Problem with a language word problem baobei 17 7,838 Mar-21-2020, 04:22 PM
Last Post: baobei
  print a word after specific word search evilcode1 8 4,822 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  difference between word: and word[:] in for loop zowhair 2 3,667 Mar-03-2018, 07:24 AM
Last Post: zowhair

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020