Author: admin
Home > Articles posted by admin (Page 60)
Question:
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed.
Input
The input will consist of several instances of the problem. Each instance begins with a line containing two...
Question:
Use the recursion we have learn in the class, please try to create a function to recursively calculate the total of 1 + 2 + …. (n-2) + (n-1) + n
def total(n):
# please write you program below
total(int(input('Please enter a number:')))
Class Notes:
All...
Question 1:
Create a Tank class which have the attributes of:
model
direction(use ‘up’, ‘down’, ‘left’ or ‘right’)
x position and
y position
The class also have the following method:
move () method can change the x or y position by 10 base on the tank’s direction. (‘up’...
Posted at 18:03h
in
Uncategorized
by admin
Question:
Create a loop between 1 to 20.
Print “fizz” if the number is divisible by 3
Print “bizz” if the number is divisible by 5
Print “fizzbizz” if a number is divisible by both 3 and 5.
Otherwise, print the number itself.
Hint: You should use...
Posted at 18:01h
in
Uncategorized
by admin
Question 1:
Use while loop (NOT for loop) to create the multiplication table program. After asking which table the user wants, ask her how high the table should go. The output should look like this:
Sample Input:
Which multiplication table would you like? 7
How high do you want to go?...
Question:
A fish-finder is a device used by anglers to find fish in a lake. If the fish-finder finds a fish, it will sound an alarm. It uses depth readings to determine whether to sound an alarm. For our purposes, the fish-finder will decide that a...
Posted at 17:54h
in
Uncategorized
by admin
Question 1:
A store is having a sale. They’re giving 10 percent off purchases of $10 or lower, and 20 percent off purchases of greater than $10. Write a program that asks the purchase price and displays the discount (10% or 20%) and the final price.
Sample Input...
Question:
Annie has two favourite baseball teams: the Eagle and the Warrior. She has followed them throughout the season, which is now over. The season lasted for N days. Both teams played exactly one game on each day.
For each day, Annie recorded the number of runs scored by...
Question:
You supervise a small parking lot which has N parking spaces. Yesterday, you recorded which parking spaces were occupied by cars and which were empty. Today, you recorded the same information. How many of the parking spaces were occupied both yesterday and today?
Input Specification:
The first line of input contains the...
Posted at 03:08h
in
Uncategorized
by admin
Question 1:
Use while loop (NOT for loop) to create the multiplication table program. After asking which table the user wants, ask her how high the table should go. The output should look like this:
Sample Input:
Which multiplication table would you like? 7
How high do you want to...