Showing posts with label intermediate. Show all posts
Showing posts with label intermediate. Show all posts

9/11/22

Registration System

 You are making a registration form for a website.

The form has a name field, which should be more than 3 characters long.

Any name that has less than 4 characters is invalid.

Complete the code to take the name as input, and raise an exception if the name is invalid, outputting "Invalid Name". Output "Account Created" if the name is valid.

Sample Input

abc

Sample Output

Invalid Name

Shooting Game

 You are creating a shooting game!

The game has two types of enemies, aliens and monsters. You shoot the aliens using your laser, and monsters using your gun.

Each hit decreases the lives of the enemies by 1.

The given code declares a generic Enemy class, as well as the Alien and Monster classes, with their corresponding lives count.

It also defines the hit() method for the Enemy class.

You need to do the following to complete the program:

1. Inherit the Alien and Monster classes from the Enemy class.

2. Complete the while loop that continuously takes the weapon of choice from user input and call the corresponding object's hit() method.

Sample Input

laser

laser

gun

exit

Sample Output

Alien has 4 lives

Alien has 3 lives

Monster has 2 lives

9/9/22

Spelling Backwards

 Given a string as input, use recursion to output each letter of the strings in reverse order, on a new line.

Sample Input

HELLO

Sample Output

O

L

L

E

H

9/8/22

Letter Counter

 Given a string as input, you need to output how many times each letter appears in the string.

You decide to store the data in a dictionary, with the letters as the keys, and the corresponding counts as the values.

Create a program to take a string as input and output a dictionary, which represents the letter count.

Sample Input

hello

Sample Output

{'h': 1, 'e': 1, 'l': 2, 'o': 1}

Contact Search

 You are given a list of contacts, where each contact is represented by a tuple, with the name and age of the contact.

Complete the program to get a string as input, search for the name in the list of contacts and output the age of the contact in the format presented below:

Sample Input

John

Sample Output

John is 31

National Economic Freedom

 You are working on data that represents the economic freedom rank by country.

Each country name and rank are stored in a dictionary, with the key being the country name.

Complete the program to take the country name as input and output its corresponding economic freedom rank.

In case the provided country name is not present in the data, output "Not found".

9/7/22

Car data

 You are working at a car dealership and store the car data in a dictionary:

car = {

    'brand': 'BMW',

    'year': 2018,

    'color': 'red'

}

Your program needs to take the key as input and output the corresponding value.

Sample Input

year

Sample Output

2018

Blog Archive