Question

1. Write a Python program that will determine if the user can vote or not. The program will ask the user to enter integer num

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code Screenshot :

#Prompting the user for bday inputs birth_year int(input(Please enter year of birth: )) birth_month int(input(Please enter

Executable Code:

#Prompting the user for bday inputs
birth_year = int(input("Please enter year of birth: "))
birth_month = int(input("Please enter month of birth: "))
birth_day = int(input("Please enter day of birth: "))

#Prompting the user fo current day inputs
current_year = int(input("\nPlease enter Current year: "))
current_month = int(input("Please enter Current month: "))
current_day = int(input("Please enter Current day: "))


#Checking if the user can vote
if (current_year - birth_year)==18:
   if (current_month == birth_month):
       if(current_day>=birth_day):
           print("\nCongrats, you can vote")
       else: print("\nSorry you cannot vote")
   elif(current_month>birth_month):
       print("\nCongrats, you can vote")
   else: print("\nSorry you cannot vote")
elif (current_year - birth_year)>18:
   print("\nCongrats, you can vote")
else:
   print("\nSorry you cannot vote")

Sample Output:

Please enter year of birth: 1970 Please enter month of birth: 8 Please enter day of birth: 20 Please enter Current year: 2019

Please enter year of birth: 2005 Please enter month of birth: 2 Please enter day of birth: 5 Please enter Current year: 2020

Please comment below if you have any queries.
Please do give a thumbs up if you liked the answer thanks :)

Add a comment
Know the answer?
Add Answer to:
1. Write a Python program that will determine if the user can vote or not. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python Write a program that reads the date of birth from the user as 3...

    in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...

  • Write a program that prompts the user to enter a person's birth date in numeric form...

    Write a program that prompts the user to enter a person's birth date in numeric form (e.g. 8-27-1980) and outputs the date of birth in the format of month day, year (e.g. August 27, 1980). Your program must work for three types of exceptions - invalid day, invalid month and invalid year (year must be between 1915 and 2015). Make these as class driven exceptions. Use one try-catch block with separate catches for the exception classes to handle errors for...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • Q1: Write a Java program that will display different messages depending on your age. Your program...

    Q1: Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on...

  • Task 1 Write a Python program that reads in any number of birth years until the...

    Task 1 Write a Python program that reads in any number of birth years until the number zero is entered. The program will then print out the average age and how old the youngest and oldest, respectively. For this task, you can start from the pseudo-code (separately) you received to get started. Example of program execution (user entries in numbers (year)): Enter year of birth. To finish, enter the number 0. Year: 1998 Year: 1932 Year: 1887 Error: Unreasonable year....

  • 1) Write a Python program that prompts the user to enter the current month name and...

    1) Write a Python program that prompts the user to enter the current month name and prints the season for that month. Hint: If the user enters March, the output should be "Spring"; if the user enters June, the output should be "Summer". 2 )Write a Python program using the recursive/loop structure to print out an equilateral triangle below (double spacing and one space between any two adjacent asterisks in the same row).          *      * * * *...

  • Write a C program which creates a template for a structure to store somebody's date of...

    Write a C program which creates a template for a structure to store somebody's date of birth (day, month, and year). Then write a C function that takes two such structure, one which represents the date of birth, and the other today's date, and returns the age of the user in years. Your function can either provide the full year only (integer) or the floating point age (bonus marks). Next, write a C program which asks the user to enter...

  • USE IDLE PLATFORM FOR PYTHON PLEASE Write a Python program that creates a list that contains...

    USE IDLE PLATFORM FOR PYTHON PLEASE Write a Python program that creates a list that contains players of your favorite teams. The program then should ask the user to enter the name of a player. If the player is in your list, display a message indicating that the player is in the team. Otherwise, the program should display a message stating that the player isn't on the team.

  • Write a program in Python that asks the user for the ISBN of the book in...

    Write a program in Python that asks the user for the ISBN of the book in the format xxx-x-xxx-xxxxx-x. To validate: Initialize a total to 0 Have the program remove the dashes so that only the 13 digits are left in the ISBN string for each index of the first 12 digits in the 13 digit ISBN string get the digit at the current index as an integer If the current index is an even number, add the digit to...

  • Write a program in visual c# program named CheckMonth that prompts a user to enter a...

    Write a program in visual c# program named CheckMonth that prompts a user to enter a birth month. If the value entered is greater than 12 or less than 1, display an error message; otherwise, display the valid month with a message such as 3 is a valid month.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT