vendredi 15 octobre 2021

Program to check west coast StateCodes

Looking to discuss possible solutions for the program Function trivia below

In the newest version of Python:

Output: Please enter one of the following options: 1 to check if a state is on the West Coast 2 to output a rectangle with random length and height, both between 2-10 3 to input a number and check if it is divisible by both 2 and 3, or if it's odd, or even, but not divisible by 3 4 to practice calculations and loops: 1 Enter 2-letter state code: CA That state is on the West Coast Use the following without changing the code given:

import random

def main():
    print("Please enter one of the following options:")
    print("1 to check if a state is on the West Coast")
    print("2 to output a rectangle with random length and height, both between 2-10")
    print("3 to input a number and check if it is divisible by both 2 and 3,")
    print("  or if it's odd, or even, but not divisible by 3")
    print("4 to practice calculations and loops: ")
    choice = int(input())    
    if choice == 1:
        state = input("Enter 2-letter state code: ")
        if checkWestCoast(state):
            
    # WRITE YOUR CODE HERE


def checkWestCoast(stateCode):
    '''
    Returns a Boolean value: 
    True if the 2-letter state code is for a west-coast US state.
    '''
    # WRITE YOUR CODE HERE


def randomRect():
    '''
    Outputs a rectangle with random length and height, both between 2-10
    '''
    # WRITE YOUR CODE HERE
        

main()

My code so far

import random

def main():
  print("Please enter one of the following options:")
  print("1 to check if a state is on the West Coast")
  print("2 to output a rectangle with random length and height,both between 2-10")
  print("3 to input a number and check if it is divisible by both 2and 3,")
  print("  or if it's odd, or even, but not divisible by 3")
  print("4 to practice calculations and loops: ")
  choice = int(input())    
  if choice == 1:
    state = input("Enter 2-letter state code: ")
  # if checkWestCoast(state):
  #     print("test")
  #   # WRITE YOUR CODE HERE

def randomRect():
  rows = random.randint(1, 20)
  columns = random.randint(1, 20)

  print("Rectangle Star Pattern") 
  for i in range(rows):
    for j in range(columns):
        print('*', end = '')
    print()

def checkWestCoast(stateCode):
  westCoastStates = ("CA","HI","Ak","WA","OR")
  if stateCode == westCoastStates:
    print("yes")
    '''
    Returns a Boolean value: 
    True if the 2-letter state code is for a west-coast US state.
    '''


        

main()



Aucun commentaire:

Enregistrer un commentaire