Programming Fundamental Assignment
Programming Fundamental Assignment
ASSIGNMENT NO:01
Short Answers [Marks: 02]
1. What is pseudo-code? State the difference between an algorithm and the pseudo-code
of any given problem?
Pseudo-code:
Algorithm:
1. Start
2. Input (number x)
3. Input (number y)
4. Product = x *y
5. Print (product)
6. End
Pseudo- code:
Start program
Enter any two numbers
Multiply both of them
Print the product of them
End program
2. Explain what is meant by the term “conditionally executed.”
A conditionally executed statement is performed only when a certain condition is true. You
need to test a condition and then execute one set of statements if the condition is true. If the
condition is false, you need to execute a different set of statements
A Condition-Controlled loop keeps going until a certain condition is met, like say the user clicks
a button A Condition-Controlled loop keeps going until a certain condition is met, like say the
user clicks a button
A sentinel is a special value that marks the end of the list of values. A big advantage of using
sentinel values is that there is no limit to how many times a loop can execute and when a
program reads a sentinel value, it knows it has reached the end of the list, so the loop
terminates.
Python represents all its data as objects. An object’s mutability is determined by its type. Some
of these objects can change their content without changing their identity while Other objects
like integers, floats, strings and tuples are objects that cannot be changed, added or modified.
6. Assume the variable sales references a float value. Write a statement that displays the
value rounded to two decimal points.
Print('%.2f'%sales)
Write algorithm and make flowchart of the following:
1.Tip, Tax, and Total: A program that calculates the total amount of a meal purchased at a
restaurant. The program should ask the user to enter the charge for the food, and then
calculate the amount of a 15 percent tip and 7 percent sales tax. Display each of these amounts
and the total.
Algorithm:
1. Start
2. Input (charge)
3. Tip = charge*0.15
4. Sales tax = charge*0.07
5. Total = charge+ tip + sales tax
6. Print (charge)
7. Print (tip)
8. Print (sales tax)
9. Print (total)
10. End
Flowchart:
1. Magic Date: The date June 10, 1960, is special because when it is written in the following
format, the month times the day equals the year:
6/10/60
Design an algorithm that asks the user to enter a month (in numeric form), a day, and a two
digit year. The program should then determine whether the month times the day equals the
year. If so, it should display a message saying the date is magic. Otherwise, it should display a
message saying the date is not magic.
ALGORITHM:
1. Start
2. int (input (day))
3. Int (input (month))
4. Int (input (last two digit of year))
5. Date = day * month
6. If (date==year):
7. Print (It is a magic date.)
8. Else:
9. Print (It is not a magic date.)
10. End
Flow chart:
1. Write a program that asks the user to enter the amount that he or she has budgeted for a
month. A loop should then prompt the user to enter each of his or her expenses (title and
amount) for the month, and keep a running total. When the loop finishes, the program should
display the amount and inform the user that he or she is over or under budget. The program
should also display Total expenses with their title.
Sample Output:
What is your budget for the previous month?
30000
Enter your expenses with their purpose/title
Food items 5000
Any other expense? Y
Clothes 5000
Any other expense? N
Good Job! You saved 20000 from your previous month. Here are your details
Total Budget: 30000
Food items: 5000
Clothes: 5000
Remaining Budget: 20000
Thank You!
Program code:
Output:
2. The area of a rectangle is the rectangle’s length times its width. Write a program that asks
for the length and width of five rectangles. The program should display the rectangles in
descending order according to their area and tell the user which rectangles have the same area
if any.
Program code:
Output:
3. The colors red, blue, and yellow are known as the primary colors because they cannot be
made by mixing other colors. When you mix two primary colors, you get a secondary color, as
shown here:
When you mix red and blue, you get purple.
When you mix red and yellow, you get orange.
When you mix blue and yellow, you get green.
Design a program that prompts the user to enter the names of two primary colors to mix. If the
user enters anything other than “red,” “blue,” or “yellow,” the program should display an error
message. Otherwise, the program should display the name of the secondary color that results.
Program code:
Output: