Day 1 — Band Name Generator

Glory Odeyemi
4 min readOct 20, 2023

--

Image from here.

I recently started taking the Udemy 100 Days of Code: The Complete Python Pro Bootcamp for 2023 course, and in this series, I will be providing my solutions to the challenges and projects. So sit back and enjoy the ride!

The goal of the first project — Band Name Generator, is to generate a band name using the city and pet name provided by the user. To achieve this, we will cover four topics in the Python programming language: comments, input()function, print() function, string manipulation, and variables.

Comments, Variables & input() Function

The input() function allows input from the user and returns it as a string, and you can view a variable as a memory location where a value is stored. Comments allow you to explain your code or make it more readable, and it does not affect the output of your code, i.e., Python does not execute a comment with the rest of your code. Below is the syntax for Python's input() function, comment, and variable.

# I am a comment
name = input("Enter your name: ")

name - represents the variable storing the input gotten from the user

"Enter your name: " - represents the input prompt. A default message displayed before the user input.

# I am a comment - represents a Python comment. It usually starts with a # symbol.

Now that we know Python's input() function, comment, and variable, let's apply them to our project.

The first step in creating our band name generator is to ask the user for the city they grew up in and the name of a pet.

# Ask the user for the city that they grew up in.
city = input("What city did you grow up in?\n")

# Ask the user for the name of a pet.
pet = input("What is the name of a pet?\n")

The code above allows the user to enter the city they grew up in and the name of a pet, which is then stored in the city and pet variables respectively.

String Manipulation and print() Function

The Python print() function displays a specified message to the screen or output device. Strings are usually denoted by either single quotation marks '' or double quotation marks "".

# Syntax for a string
my_string1 = "I am a string"
my_string2 = 'I am also a string'

# String manipulation - concatenation
my_string = my_string1 + " and " + my_string2

# Syntax for the print() function
print(my_string)

When the above code is executed, I am a string and I am also a string will be displayed as an output because of the print() function. The + operator is used to concatenate, i.e., combine two strings. Let's apply this new knowledge to our project.

# Combine the name of their city and pet and show them their band name.
band_name = city + " " + pet
print("Your band name is: " + band_name)

We have been able to generate a band name from the user’s city and a pet name using Python input() and print() functions, variables, and string concatenation. Let's combine all the codes.

# Ask the user for the city that they grew up in.
city = input("What city did you grow up in?\n")

# Ask the user for the name of a pet.
pet = input("What is the name of a pet?\n")

# Combine the name of their city and pet and show them their band name.
band_name = city + " " + pet
print("Your band name is: " + band_name)

The output of the code will look like;

Image from author

We now have our band name, and if you happen to see Major Snoopy topping the charts, just know I have decided to start a band and given it that name😅.

Conclusion

If you made it this far, I commend your determination to learn, and I appreciate you sticking with me. With the new knowledge you have, feel free to customize your code. You can test the band name generator below or view the complete code.

Have fun coding your band name generator. See you in the next one!

--

--