This content originally appeared on DEV Community and was authored by Jonathan Cohen
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.")
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)
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
This content originally appeared on DEV Community and was authored by Jonathan Cohen
Jonathan Cohen | Sciencx (2021-08-09T20:21:24+00:00) New Beginnings. Retrieved from https://www.scien.cx/2021/08/09/new-beginnings/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.