0% found this document useful (0 votes)
40 views

Assignment 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Assignment 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Ahmedabad University

School of Engineering and Applied Science


Course: CSE100 Fundamentals of Computer Programming
Programming Assignment – 1
Submission Date: On or Before December 10, 2020

Instructions

 First design algorithms or flowchart for the following problems and then implement the same using ‘Python’
programming language. Create flowchart of any 5 problems and Algorithm/Pseudo code for any 5 problems.
 Use meaningful and descriptive variable/identifier names:
Good variable names (camelCase): rollNo, studentName, empSalary, salesPrice, taxRate,
 Every Program should have header and footer having following information in multi-line comments
'''
@author: RollNo Firstname Lastname
@description: Program No. - write short purpose/ description here
'''
 Every Program should have footer with output of the Program in multi-line comment
''' PROGRAM OUTPUT
'''
 Submission details: Submit your assignment on lms.ahduni.edu.in before the given submission date. Create
one .ZIP file containing all Python programs (.py files) and one word file (containing 5 Algorithms and 5
Flowcharts). Keep filename as RollNo-Name-Assignment1.zip. Keep your file size less than 10MB.
 Programs submitted by a student should be the result of individual work based on his/her own efforts. Full or
part of the code should not be copied from internet or from peer students or other sources. A student should
not share/circulate the code/programs developed by them (for individual assignments) with their peers in any
form. Violation of above will be considered as academic dishonesty and any such case will be strictly dealt with
and liable to get zero in the evaluation.

Write a Python program to solve the following problem definition:

1. Write a Python program to read and print your name (Concept to learn: Getting familiar
with Python IDE, User input and output).
2. Write a Python program to print your ID – Card (Concept to learn: Formatted output).
3. Write a Python program to input a number and check whether the entered number is even
or odd.
4. Write a Python program to check whether a number is divisible by 5 or not.
5. Write a Python program to read a month number and print corresponding month name.
Sample output:
Enter Month Number: 11
November
6. Write a Python program to find the Square Root of a given number.

Page 1
7. Write a Python program to input angles of a triangle and check whether triangle is valid or
not.
8. Write a Python program to calculate the Area of a Triangle.
9. Write a Python program to check whether a person is eligible to vote or not.
10. Write a Python program to Generate and print a Random Number.
11. Write a Python program to Convert Celsius to Fahrenheit.
12. Write a Python program to make a Simple Calculator.
13. Write a Python program to print the sum of first 10 numbers.
14. Write a Python program to input 3 numbers from user and print the maximum among
them. (with conditional operator)
15. Write a program to find the sum of odd numbers and even numbers from 1 to N, N entered
by the user.
16. Create a converter that will convert a distance in meters to feet and inches.
Enter length in meters: 1
1.00m = 3 feet and 3.37 inches

Conversion formula:
1 feet = meters * 3.281
1 Feet = 12 inch

17. Write a Python program to read a character from the user and check whether it is a vowel
(aeiou) or consonant.
18. Write a program to check whether a character is uppercase or lowercase alphabet.
19. Write a program to accept two numbers and one mathematical operator. Calculate and
display appropriate answer as shown below:
Sample output:
Enter first number : 5
Enter mathematical operator : +
Enter second number : 6
5 + 6 = 11
20. Write a program to enter a number from the user and display the sum of all the digits in the
number.
21. Accept a year from the user and check whether it is leap year or not.
The normal year contains 365 days but the leap year contains 366 days. This extra day is added to the
February month, that’s why we get February 29. All the years that are perfectly divisible by 4 are called as
Leap years except the century years. Century year’s means they end with 00 such as 1200, 1300, 2400, 2500

Page 2
etc (Obviously they are divisible by 100). For these century years we have to calculate further to check the
Leap year.
- If the century year is divisible by 400 then that year is a Leap year
- If the century year is not divisible by 400 then that year is a Leap year

22. Write a program called ExtractDigits to extract each digit from an int in the reverse order. For
example, if the int is 12345, the output shall be "5 4 3 2 1", with a space separating the digits.
23. Accept a number N from the user and print the first N elements of the Fibonacci series.
Hint: The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21
Fibonacci series is defined as a sequence of numbers in which the first two numbers are 1 and 1, or 0
and 1, depending on the selected beginning point of the sequence, and each subsequent number is
the sum of the previous two. So, in this series, the nth term is the sum of (n-1)th term and (n-2)th term.
Mathematically, the nth term of the Fibonacci series can be represented as:
tn = tn-1 + tn-2

24. Calculate the area of triangle given its three sides. The formula or algorithm used is:
Area = sqrt(s(s – a)(s – b)(s – c)), where s = (a + b + c) / 2 or perimeter / 2 and a, b & c are
the sides of triangle.

25. Write a program that take input of 3 subjects marks out of 150. Count the percentage. Print
the Grade/Class based on following conditions:
 For 70% or more than 70% display DISTINCTION.
 For percentage between 60 and 69 display FIRST CLASS.
 For percentage between 50 and 59 display SECOND CLASS.
 For percentage between 40 and 49 display PASS CLASS.
 For percentage less than 40 display FAIL.
26. Accept the marks (out of 70) for 3 subjects (Maths, physics, chemistry) from the user and
check if the student is eligible for admission based on the following criteria:
i) Mathematics >= 50%, Physics >= 45%, Chemistry >= 60%, and Overall Percentage >= 65%
OR
ii) Total marks of Mathematics + Physics >= 120
Page 3
27. Considering three numbers provided by the user as length of sides of a triangle, first check, if
the values are valid for representing the sides of a triangle (i.e. whether a triangle can be
drawn using the given values). If the lengths of sides are valid, print the type of the triangle.

Hint: The sum of lengths of any two sides of a triangle is always greater than the length of
the third side. A triangle with all three sides having same length is known as an “Equilateral”
triangle. A triangle is called an “Isosceles” triangle if only two sides have equal lengths. If all
the sides of a triangle have different lengths, then it is called a “Scalene” triangle.

28. Write to program to print following series using looping concept (use while or for loop).
A. 1, 2, 3, 4 ........ 100
B. 100, 99, 98.......1
C. 1, 3, 5, 7........99
D. 2, 4, 8, 16, 32, 64
29. Write a program to print following pattern. (hint: nested for loop)
A
BB
CCC
DDDD

30. Print multiplication table of a number entered by the user. Validate that the number must
be between 1 and 20. E.g.
5X1=5
5 X 2 = 10
5 X 3 = 15
………..
5 X 10 = 50

Practice Questions

Note: The below questions are for practice and NOT required to be submitted as
part of assignment submission.

1. Accept the basic salary of an employee from the user, and calculate the gross salary using :
Gross Salary = Basic Salary + DA + HRA – PF
DA = 30% of Basic Salary If Basic Salary < 5000 otherwise DA = 45% of the Basic Salary.
HRA = 15% of Basic Salary.
PF = 12% of Basic Salary.

2. An equation of the form


Page 4
is known as the quadratic equation. The values of x that satisfy the equation are known as
the roots of the equation. A quadratic equation has two roots which are given by the following
two formula
−𝑏 − √𝑏 2 − 4𝑎𝑐
𝑟𝑜𝑜𝑡1 =
2𝑎
−𝑏+ √𝑏2 −4𝑎𝑐
𝑟𝑜𝑜𝑡2 = 2𝑎
Write a program that requests the user to input the values of a,b, and c and outputs root1
and root2.

3. Read an employee name (NAME), overtime hours worked (OVERTIME), hours absent
(ABSENT) and determine the bonus payment (PAYMENT).

Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid
>40 hours $50
>30 but  40 hours $40
>20 but  30 hours $30
>10 but  20 hours $20
 10 hours $10

4. Display this kind of output on screen (if user enters N=4).


10 9 8 7
654
32
1
5. Write a program to print following pattern. (hint: nested for loop)
@@@@@@
@@@@@
@@@@
@@@
@@
@

Page 5

You might also like