198k views
1 vote
A person is eligible to be a US senator if they are at least 30 years oldand have been a US citizen for at least 9 years. To be a US representativethese numbers are 25 and 7, respectively. Write a program that accepts aperson's age and years of citizenship as input and outputs their eligibilityfor the Senate and House.

User Gorsky
by
4.4k points

2 Answers

6 votes

Answer:

age = int(input("Your age: "))

citizen = int(input("Years of being a US citizen: "))

if age >= 30 && citizen >= 9:

print("You are eligible to US representative and a US senator")

elif age >= 25 && citizen >= 7:

print("You are eligible to be a US representative")

else:

print("You are not eligible to be a US representative or US senator")

Step-by-step explanation:

Ask the user for its age, and years of citizenship

Check the both inputs:

If age is greater than or equal to 30 and citizen is greater than or equal to 9, it means the person is eligible for US representative and a US senator

If age is greater than or equal to 25 and citizen is greater than or equal to 7, it means the person is eligible for US representative

In any other case, the person is not eligible

User Abraham Labkovsky
by
5.1k points
7 votes

Answer:

import java.util.Scanner;

public class num1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

//Prompt for the person's age

System.out.println("What is your age");

int age = in.nextInt();

//Prompt for the person's years of citizenship

System.out.println("What is your years of citizenship");

int yearsCitizenship = in.nextInt();

if(age >= 30 && yearsCitizenship >= 9){

System.out.println("You are Eligible to be a US senator");

}

if(age >= 25 && yearsCitizenship >= 7){

System.out.println("You are Eligible to be a US representative");

}

}

}

Step-by-step explanation:

Using Java Programming language

The scanner class is used to receive and store the persons age and year of citizenship

The first if statement is used to test if the age >= 30 and citizenship>=9 If this is true, it prints out You are Eligible to be a US senator. You are Eligible to be a US representative. Note that if the second condition is true, then the first is also true because to be eligible for senatorial also means you also meet the requirments for representative position

User Galakt
by
5.0k points