Showing posts with label sololearn. Show all posts
Showing posts with label sololearn. 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}

Fruit Bowl

 You have a bowl on your counter with an even number of pieces of fruit in it. Half of them are bananas, and the other half are apples. You need 3 apples to make a pie.

Task

Your task is to evaluate the total number of pies that you can make with the apples that are in your bowl given to total amount of fruit in the bowl.

Input Format

An integer that represents the total amount of fruit in the bowl.

Output Format

An integer representing the total number of whole apple pies that you can make.

Sample Input

26

Sample Output

4

Popsicles

 You have a box of popsicles and you want to give them all away to a group of brothers and sisters. If you have enough left in the box to give them each an even amount you should go for it! If not, they will fight over them, and you should eat them yourself later.

Task

Given the number of siblings that you are giving popsicles to, determine if you can give them each an even amount or if you shouldn't mention the popsicles at all.

Input Format

Two integer values, the first one represents the number of siblings, and the second one represents the number of popsicles that you have left in the box.

Output Format

A string that says 'give away' if you are giving them away, or 'eat them yourself' if you will be eating them yourself.

Sample Input

3 9

Sample Output

give away


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

Search Engine

 You’re working on a search engine. Watch your back Google!

The given code takes a text and a word as input and passes them to a function called search().

The search() function should return "Word found" if the word is present in the text, or "Word not found", if it’s not.


Sample Input

"This is awesome"

"awesome"

Sample Output

Word found


How many letters

 Write a function that takes a string and a letter as its arguments and returns the count of the letter in the string.

Sample Input

hello, how are you?

o

Sample Output

3

Explanation: The letter o appears 3 times in the given text.

From feet to inches

 You need to make a function that converts a foot value to inches.

1 foot has 12 inches.

Define a convert() function, that takes the foot value as argument and outputs the inches value.

Shouting text

 Your friend is sending you a text message, however his caps lock is broken and the whole message is in uppercase.

Noone likes being shouted at, plus uppercase text is hard to read, so you decide to write a program to convert the text to lowercase and output it.

Take a string as input and output it in lowercase.

Analyze to realize

 You’re analyzing a data set and need to remove the outliers (the smallest and largest values.

The data is stored in a list).

Complete the code to remove the smallest and largest elements from the list and output the sum of the remaining numbers.

Sum of Consecutive Numbers

 No one likes homework, but your math teacher has given you an assignment to find the sum of the first N numbers.

Let’s save some time by creating a program to do the calculation for you!

Take a number N as input and output the sum of all numbers from 1 to N (including N).

Sample Input

100

Sample Output

5050

Explanation: The sum of all numbers from 1 to 100 is equal to 5050.

9/6/22

Flip the string

 Reversing a string is a common task during coding interviews.

Given a string as input, output its reverse.

Sample Input

hello world

Sample Output

dlrow olleh

Nearest Bathroom

 A group of buildings have restrooms on every 5th floor.

For example, a building with 12 floors has restrooms on the 5th and 10th floors.

Create a program that takes the total number of floors as input and outputs the floors that have restrooms.

Sample Input

23

Sample Output

5

10

15

20

Let's go shopping

 You’re making a shopping cart program.

The shopping cart is declared as a list of prices, and you need to add functionality to apply a discount and output the total price.

Take the discount percentage as input, calculate and output the total price for the shopping cart.

Just say it

 You’re making a voice recognition system.

The supported commands are stored in a list.

Complete the program to take a command as input, check if it’s supported and output "OK", if it is, and "Not supported", if not.

Sample Input

Lights Off

Sample Output

OK


9/5/22

Name please

 You need to take the first and last name of a person as input and output the initials (first letters of the first and last name).

Sample Input

James

Smith

Sample Output

J.S.

Blog Archive