User Name and Initial Printout Programming
Assignment 3
- Write a python assignmentprogram that asks for the user’s full name and then prints their initials.
- Write a program that asks for the user’s birthday in the format of “MM/DD/YYY” and then prints the month they were born in letters. For instance, if the user enters: 01/01/1990, the code should print “January”. Also if the person was born after 1997, the code should print “You are Gen Z”.
- Write a program that keeps asking for the user’s favorite foods and stops when the user types “done”. Then if the user has entered “Pizza” as one of their favorite foods, it should print “You do not have a healthy diet”, otherwise it should print “You have a healthy diet”.
- Write a program that asks for the user’s opinion on the new iPhone. Define 2 lists of keywords for battery and camera. Then based on those keywords, your code should decide if the review is about battery, about the camera, about both, or about none of them.
Solution:
def main(): name = input("Enter your full name: ") words = name.split(" ") for word in words: print(word[0].upper() + ".", end = " ") if __name__ == '__main__': main()
def main(): months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] date = input("Please enter your birthday in format (MM/DD/YYYY): ") ind = date.split("/") print(months[int(ind[0]) - 1]) if int(ind[2]) > 1997: print("You are Gen Z.") if __name__ == '__main__': main()
def main(): entry = "" output = "You have a healthy diet" while entry.lower() != "done": entry = input("Enter a food you like: ") if entry.lower() == "pizza": output = "You do not have a healthy diet" print(output) if __name__ == '__main__': main()
def main(): battery = ["battery", "large", "backup", "mah", "li", "lithium", "hours"] camera = ["camera", "sharp", "picture", "photo", "mega", "pixel", "zoom", "clarity"] review = input("Enter your opinion about iPhone: ") words = review.lower().split(" ") isBattery = False isCamera = False for word in words: if word in battery: isBattery = True elif word in camera: isCamera = True if isBattery and isCamera: print("Review is about both battery and camera") elif isBattery: print("Review is about battery") elif isCamera: print("Review is about camera") else: print("Review is neither about battery nor camera") if __name__ == '__main__': main()
Similar Samples
Explore our curated selection of programming homework samples to see the quality and depth of our solutions. Each sample represents our expertise in various programming languages and demonstrates our dedication to delivering clear, effective coding solutions. See how we can assist you in mastering programming concepts and achieving academic success.
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python