DEV Community

Jonathan Cohen
Jonathan Cohen

Posted on

New Beginnings

As a dev, I find myself constantly thinking about the variety of languages that are out there and if there's one that I would "prefer" over the others. While I can see why that mindset could be a harmful one to a developers.....development, it's still a thought that occasionally crosses my mind. In cases like these it never hurts to feed the curiosity though.

I recently started a Udemy Python Course. I decided to finally take the chance to see what it was all about. So far I've been able to successfully create a bandname generator. To achieve this, I had to become familiar with the print function, the input function and variable assignment within the language.

Note: I've been working within an environment on Replit.com So for right now the playground is set up for me. As I learn how to run a script in console I will, then, be more detailed about all the proper steps.

Already bringing an understanding of strings from my time in JS and Ruby helped to get a quick understanding of using print(). Using it to print the greeting of the generator my first line of code was simply:

print("Welcome to the Band Name Generator.")
Enter fullscreen mode Exit fullscreen mode

After, there are 2 questions that gets asked about the name of your hometown and the name of your pet. Following both questions, on a new line you see the program continuing to run awaiting for the user to type the response and press enter. After inputting both responses the user is then met with their possible band name.

city = input("What's name of the city you grew up in?\n")

pet = input("What's your pet's name?\n")

print("Your band name could be " + street + " " + pet)
Enter fullscreen mode Exit fullscreen mode

The final print statement, without variable assignment, could definitely be a very wordy line of code. Instead, we assign the results of the input function(what the user inputs when prompted) to the variables city and pet. Finally we use string concatenation within the second print function to tie the final line of the generator together.

Note:With concatenation you should be mindful to think of spacing within the sentence.

Your band name could be Charleston Folly
Enter fullscreen mode Exit fullscreen mode

Discussion (3)

Collapse
cjsmocjsmo profile image
Charlie J Smotherman

Running a python program is easy. Place your code in a file lets say "test.py".
Now to run this code in the terminal run "python3 test.py" and that's it.

Although this code is perfectly fine

print("Your band name could be " + street + " " + pet)

the more pythonic way would be

print("Your band name could be {} {}".format(street, pet))

Happy Coding

Collapse
cjsmocjsmo profile image
Charlie J Smotherman

You can also use "join"

ace = " ".join(("Your band name could be", street, pet))
print(ace)
Enter fullscreen mode Exit fullscreen mode
Collapse
jdc1492 profile image
Jonathan Cohen Author

That’s clever as well. Thanks so much for taking the time to read the post and comment!