0% found this document useful (0 votes)
4 views3 pages

Student Details and Fibonacci Programs

The document contains programming exercises in Python, including reading student details and calculating total marks and percentage, determining if a person is a senior citizen based on their birth year, generating a Fibonacci sequence, and calculating the factorial of a number. Each exercise includes code snippets and example outputs. The document serves as a lab manual for learning basic programming concepts using Jupyter Notebook.

Uploaded by

movieshere471
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Student Details and Fibonacci Programs

The document contains programming exercises in Python, including reading student details and calculating total marks and percentage, determining if a person is a senior citizen based on their birth year, generating a Fibonacci sequence, and calculating the factorial of a number. Each exercise includes code snippets and example outputs. The document serves as a lab manual for learning basic programming concepts using Jupyter Notebook.

Uploaded by

movieshere471
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

3/2/23, 10:29 PM Lab_ManuaI_22PLC153-v1.

1 - Jupyter Notebook

1 a. Develop a program to read the student details like Name,


USN, and Marks in three subjects. Display the student details,
total marks and percentage with suitable messages.
In [4]:

1 name = input(”Enter the name of student: ")


2 usn = input("Enter the USN of student: ")
3 print(”Enter marks scored by students in 3 subjects:")
4 marks_physics = int(input(“Enter marks scored in physics:(MAX=100) ”))
5 marks_chemistry = int(input(”Enter marl‹s scored in chemistry:(MAX=100) ”))
6 marks_maths = int(input(”Enter marks scored in maths:(MAX=100) “))
7 total_marks : marks_physics + marks_chemistry + marks_maths
8 percentage = total_marks/3
9 print(”The details of student are : ”)
10 print(”Name: ",name)
11 print(”USN: ",usn)
12 print(”Marks scored: ”)
13 print(”Physics: “,marks_physics)
14 print(”Chemistry: ”,marks_chemistry)
15 print(”Maths: ",marks_maths)
16 print(”Total: ",total_marks)
17 print(”Percentage: {:.2f}".format(percentage))

Enter the name of student: Kirankumar K


Enter the USN of student: 1PT21EC025
Enter marks scored by students in 3 subjects:
Enter marks scored in physics:(MAX=100) 65
Enter marks scored in chemistry:(MAX=100) 70
Enter marks scored in maths:(MAX=100) 72
The details of student are :
Name: Kirankumar K
USN: 1PT21EC025
Marks scored:
Physics: 65
Chemistry: 70
Maths: 72
Total: 207
Percentage: 69.00

1 b. Develop a program to read the name and year of birth of a


person. Display whether the person is a
senior citizen or not.

localhost:8891/notebooks/Lab_ManuaI_22PLC153-[Link] 1/11
3/2/23, 10:29 PM Lab_ManuaI_22PLC153-v1.1 - Jupyter Notebook

In [17]:

1 import datetime
2 name = input(”Enter the name of person: “)
3 birth_year = int(input("Enter the year of birth of person: "))
4 today = [Link]()
5 year : [Link]
6 age = year - birth_year
7 if age›= 60:
8 print(name," is a senior citizen.”)
9 else:
10 print(name,” is not a senior citizen.“)
11
12

Enter the name of person: Sunil Patil


Enter the year of birth of person: 1985
Sunil Patil is not a senior citizen.

2 a. Develop a program to generate Fibonacci sequence of


length (N). Read N from the console.
In [1]:

1 n : int(input(”Enter the required length of Fibonacci sequence: "))


2 t1: 0
3 t2 = 1
4 print(”The first %d terms of Fibonacci series are : %d\t%d "%(n,t1,t2),end=”\t")
5 nt = 2
6 while(nt<n):
7 t3 t1+t2
8 print(”%d "%(t3),end="\t")
9 t1 t2
10 t2 t3
11 nt+:1

Enter the required length of Fibonacci sequence: 10


The first 10 terms of Fibonacci series are : 0 1 2 3 5 8
13 21 34

2 b. Write a function to calculate factorial of a number. Develop a


program to compute binomial coefficient(Given N and R).
In [ 2] :

1 def find_factorial(n):
2 result 1
3 if(n‹2):
4 return result
5 for i in range(2,n+1):
6 result*:i
7 return result
8 while(True):
9 n = int(input(“Enter any integer: "))
10 if (n›:0):
11 break
12 print(”%d! = %d"%(n,find_factorial(n)))
13

Enter any positive integer: 8


8! 40320

localhost:8891/notebooks/Lab_ManuaI_22PLC153-[Link] 2/11
Only two pages were converted.
Please Sign Up to convert the full document.

[Link]/membership

Common questions

Powered by AI

A loop structure is integral in generating Fibonacci sequences as it allows for iterative calculation and output of each sequence term. The logic lies in the nature of Fibonacci numbers, where each term after the first two is the sum of its two predecessors. Using a `while` loop effectively manages this repetitive addition, continuously updating the variables representing the two most recent numbers. This approach is memory and computation efficient, especially for large sequences, allowing dynamic user-determined sequence lengths .

The function `find_factorial` calculates the factorial of a given number by initializing a variable `result` to 1. If the input number `n` is less than 2, it immediately returns `result` as 1. Otherwise, it iterates from 2 through `n`, multiplying `result` by each integer i, effectively calculating `n!` as the product of all integers from 1 to `n`. The function then returns the computed factorial .

The program ensures correct printing of the Fibonacci sequence by reading the desired length of the sequence from the user, then initializing the first two Fibonacci numbers. Within a loop, it adds these numbers to produce subsequent terms, printing each in sequence. By controlling the loop to iterate only until the specified length is reached and updating the variables holding the last two numbers in each iteration, the program accurately generates and displays the correct sequence, aligned with user inputs .

The program reads the student's name, USN, and marks for three subjects: physics, chemistry, and maths. These marks are individually captured using the input function and converted to integers. It then calculates the `total_marks` by adding the scores of these three subjects. The `percentage` is obtained by dividing `total_marks` by three (since there are three subjects), giving the average score. This is followed by displaying the student details along with the total marks and percentage, formatted to two decimal places .

The program checks whether a person is a senior citizen by first reading their name and year of birth. Using Python's `datetime` module, it retrieves the current year, then calculates the person's age by subtracting the year of birth from the current year. If the age is 60 or above, it prints that the person is a senior citizen. Otherwise, it states that the person is not a senior citizen .

Format specifications are important in displaying percentages to ensure clarity and readability, especially for values requiring precision. In the student marks program, formatting the percentage to two decimal places makes the output more professional and easier to interpret by eliminating extraneous decimal places that could clutter information. Precision is critical in educational settings where grading depends on accurately represented scores, thus aiding both immediate comprehension and communication of significant numerical data .

In the described programs, the `input()` function is used to gather data directly from the user, such as student names, marks, and year of birth. This function is crucial for interactive programs because it allows users to provide necessary information dynamically at runtime. It is used effectively to capture necessary variables and ensure the programs can process various user-specific data scenarios, making them flexible and able to confirm to user-specific requirements .

Input validation is crucial for ensuring that the data entered is appropriate and within expected bounds before computation. For student marks, verifying input prevents the use of invalid or nonsensical numbers such as negative values or numbers exceeding subject maximums, ensuring accurate total and percentage calculations. Similarly, validating the input year of birth ensures logical and chronological consistency, preventing errors such as future birth years that could falsely influence the senior citizen status assessment, maintaining program credibility and robustness .

To compute the binomial coefficient, the program would utilize the formula `C(N, R) = N! / (R! * (N-R)!)`. The implementation uses a factorial calculation function to find the factorial of N, R, and N-R. Then, it computes the binomial coefficient by dividing the factorial of N by the product of factorial of R and factorial of N-R. This methodology follows the mathematical definition for combinations to determine how many ways R objects can be chosen from N objects .

The program generates the Fibonacci sequence by first reading the required sequence length `n` from the user. It initializes the first two Fibonacci numbers `t1` and `t2` as 0 and 1, respectively, and prints them. Using a `while` loop, it continues to generate the sequence up to the `n`th term by summing the last two numbers (`t1` and `t2`) to get the next number in the sequence (`t3`). It then updates `t1` and `t2` to the most recent two numbers and increments the loop counter `nt` until `n` is reached .

You might also like