Reputation: 41
For my homework I am supposed to create a program that takes the first name and last name from user input and randomizes the first letter of each name given. I've gone through all my notes looking for something that can do this, but unable to find it.
Example :
"First, please enter your first name: Nikki
Now, please enter your last name: Manuel
I'm going to switch the letters of your first and last name to give you a funny name! Your new name is....... Mikki Nanuel HAHA! Isn't that hilarious?"
print('Option 3! lets switch up them letters!')
f_name = input(str("Input your First Name: "))
l_name = input(str("Input your Last Name: "))
print()
print(f_name [0:1], l_name [0:1]) # This is just me trying to use anything.
print()
print('Thanks for using my program!')
This is what I have so far
Upvotes: 2
Views: 239
Reputation: 59
This code works:
import random
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
name = input("Input your name: ")
random_letter = letters[random.randint(0, len(letters)-1)]
new_name = random_letter + name[1:len(name)]
print(new_name)
Upvotes: 2
Reputation: 495
from random import *
print('Option 3! lets switch up them letters!')
f_name = input(str("Input your First Name: "))
l_name = input(str("Input your Last Name: "))
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
first_letter = randrange(1, 27)
second_letter = randrange(1, 27)
f_name[0] = letters[first_letter]
l_name[0] = letter[second_letter]
print(
f"I'm going to switch the letters of your first and last name to give you a
funny name! Your new name is: {f_name} {l_name}.")
print('Thanks for using my program!')
here is what you need.
Upvotes: 2