Q1.
A team of seismologists has gathered a sequence of recent earthquake (richter magnitude) readings from sensors around a fault line. They need a small program to analyze these magnitudes, write a program that:
- Shows how much each reading changed from the one before it.
- Finds the average reading, how spread-out the readings are and which reading happened most often.
- Counts how many different magnitudes were recorded.
- Prepares simple chart data by rounding each reading down to a whole number.
Instructions
Take the list of recorded magnitudes (at least ten values, possibly with repeats) as user input.
Calculate the amplitude ratio between each consecutive pair of magnitudes (
m1 - m2) using the formula:amplitude_ratio = 10 (m2 - m1)and store these ratios in a list, rounded to two decimal places. (This shows how many times stronger (or weaker) the second event was.)
Using the
statisticsmodule, compute and display:- mean: the average magnitude
- variance: how much the magnitudes vary overall
- mode: the most common magnitude
Convert the magnitude list into a
setto determine and display the number of distinct magnitude recorded.Prepare a list of chart bins by flooring each magnitude to the nearest whole number.
Finally, print out:
- The original magnitudes
- The amplitude ratios between each pair
- The calculated mean, variance and mode
- The count of unique magnitudes
- The list of floored chart bins
Expected Output
// input
Enter magnitudes: 3.2 4.1 3.8 5.0 4.1 3.2 4.7 5.0 4.1 3.8
// output
Original magnitudes:
[3.2, 4.1, 3.8, 5.0, 4.1, 3.2, 4.7, 5.0, 4.1, 3.8]
Amplitude ratios between each pair:
[7.94, 0.50, 15.85, 0.13, 0.13, 31.62, 1.99, 0.13, 0.50]
Magnitude stats:
Mean: 4.1
Variance: 0.42
Mode: 4.1
Number of distinct magnitudes: 5
Chart bins (floored values):
[3, 4, 3, 5, 4, 3, 4, 5, 4, 3]Q2.
A climate researcher is tracking atmospheric CO₂ concentrations over several months to understand how quickly levels are rising and to forecast when they might reach critical thresholds. They need a program that analyzes past data and makes simple future projections.
Instructions
Take a list of monthly CO₂ readings in parts per million (ppm) as user input (at least six values).
Monthly Growth Factors:
- For each consecutive pair of readings (prev, curr), compute the exact growth factor (
curr / prev) (usingFractionmodule) and then convert to a float. (This shows how many times higher the concentration is compared to the previous month.) - Store these in a list.
- For each consecutive pair of readings (prev, curr), compute the exact growth factor (
Convert each growth factor into a monthly growth rate using the natural logarithm:
rate = log(factor)(This tells the continuous rate of increase per month.)
Logarithmic Rates:
- Find the highest and lowest recorded CO₂ values using
max()andmin(). - Then compute their difference (
range_ppm = max - min) to see the overall swing.
- Find the highest and lowest recorded CO₂ values using
Future Projection (Exponential Growth):
Find the average monthly growth rate (mean of your rate list).
Project the CO₂ level 12 months from the last reading using:
projection = last_reading * (1 + average_rate)12
Threshold Timing:
Ask the user for a critical threshold value (e.g., 450 ppm).
Solve for how many whole months it will take to exceed that threshold by rearranging the exponential model:
months = log(threshold / last_reading) / log(1 + average_rate)Round this up to the next whole month with
ceil().
Finally, print out:
- The original CO₂ readings
- The list of growth factors
- The max, min, and range of readings
- The projected CO₂ after one year
- The count of unique magnitudes
- The number of months (ceiled) to reach the threshold
Expected Output
// input
Enter CO₂ readings (ppm): 400 405 410 412 415 420
Enter threshold (ppm): 450
// output
Original readings:
[400, 405, 410, 412, 415, 420]
Exact growth factors:
[81/80, 82/81, 206/205, 415/412, 84/83]
Decimal growth factors:
[1.0125, 1.0123, 1.0049, 1.0073, 1.0120]
Monthly log-rates:
[0.0124, 0.0123, 0.0049, 0.0073, 0.0120]
Max reading: 420
Min reading: 400
Range: 20
Projected CO₂ after 12 months: 471.91 ppm
Months to reach 450 ppm: 8Q3.
A road-building team has measured how steep different parts of a mountain road are. They need a small program to:
- Find each slope’s angle so they know how steep it is.
- See how gravity breaks down along and across the slope.
- Flag any sections that are steeper than what’s considered safe.
Instructions
- Take two lists (same length) as user input:
rise(vertical rise in meters)run(horizontal run in meters)
- Compute Slope Angles:
- For each pair (rise, run), calculate the slope angle in degrees:
angle_rad = atan(rise / run)angle_deg = degrees(angle_rad)
- Store all angles in a list. (This tells how many degrees above horizontal each slope is.)
- For each pair (rise, run), calculate the slope angle in degrees:
- Gravity Components:
For each
angle_rad, compute:vertical_ratio = sin(angle_rad)(i.e. rise / hypotenuse : this tells how much gravity pulls down the slope.)horizontal_ratio = cos(angle_rad)(i.e. run / hypotenuse : this tells how much gravity pulls along the slope.)
(These ratios help engineers know braking and traction needs.)
- Filter Unsafe Segments:
- Ask the user for a maximum safe angle (in degrees), (e.g. 35 degrees).
- Use built-in
filter()to select only those slopes whereangle_deg > max_safe. (These are the segments that need extra attention or redesign.)
- Finally, print out:
- for each segment:
- Rise, run
- Computed angle (°)
- Vertical and horizontal ratios
- Then separately list which segment indices (or rise/run pairs) are unsafe.
- for each segment:
Expected Output
// input
Enter rises (m): 10 20 40 8 25
Enter runs (m): 50 40 30 20 60
Enter maximum safe angle (°): 35
// output
Segment data:
1. Rise: 10, Run: 50 - Angle: 11.31° | Vertical ratio: 0.20, Horizontal ratio: 0.98
2. Rise: 20, Run: 40 - Angle: 26.57° | Vertical ratio: 0.45, Horizontal ratio: 0.89
3. Rise: 40, Run: 30 - Angle: 53.13° | Vertical ratio: 0.80, Horizontal ratio: 0.60
4. Rise: 8, Run: 20 - Angle: 21.80° | Vertical ratio: 0.37, Horizontal ratio: 0.93
5. Rise: 25, Run: 60 - Angle: 22.62° | Vertical ratio: 0.38, Horizontal ratio: 0.92
Unsafe segments (angle > 35°):
3. Rise: 40, Run: 30 → Angle: 53.13°Q4.
Write a program that asks for a person’s birthdate and then tells them their exact age - years, months and days - as of today. The program should check if the date is valid and correctly handle leap years and months of different lengths.
datetime module can be used for all the date and time related operations.
Expected Output
// case 1
Enter the birth year: 2002
Enter the birth month: 2
Enter the birth day: 2
Age: 23 years, 18 months, and 10 days
// case 2
Enter the birth year: 2028
Enter the birth month: 12
Enter the birth day: 2
Invalid birthdate! Please enter a valid date.
// case 3
Enter the birth year: 1999
Enter the birth month: 29
Enter the birth day: 2
Invalid birthdate! Please enter a valid date.Q5.
A parent has collected a list of popular baby names but wants an easy way to see all the options that begin with a given letter. Write a program that helps them quickly get the names starting with the letter they choose.
Expected Output
// names: Amiya, Aarav, Aarna, Avyaya, Anura, Barkha, Chhavi, Chaah, Dhithi, Dvij, Falak,
Hanita, Izaan, Jiyaan, Krishiv, Laya, Mahi, Moh, Navya, Nirvan, Nirmay, Nahar, Nadhiya,
Ojal. Ojas, Parishi, Praan, Rahi, Sakhi, Shay, Yuti
// case 1
Enter the first letter: N
Names found:
Nahar
Navya
Nirmay
Nirvan
// case 2
Enter the first letter: V
No names found starting with 'V'.Q6.
What will be the output of the following programs?
You have to predict the output result without running/executing the code.
I.
message = "hello" message[0] = "H" print(message)II.
message = 'code' n = message.find('ad') print(n) print(message) message.replace('od', 'abl') print(message)III.
animal_name = "cat" animal_name += "erpillar" print(animal_name)IV.
email = " [email protected] " email = email.strip() print(email) l = len(email) print(l) email.lower() print(email)V.
message = 'code' print(message[1:3]) print(message[1:]) print(message[:3]) print(message[0:3]) print(message[:]) print(message[:-3])VI.
names = "tina, meena, rina, veena" names.split(',') print(names)
Q7.
A new site wants to give each user a fun, memorable username automatically. The rule is:
- First character: the first letter of first name (lowercase)
- Next four characters: the first four letters of last name (lowercase), by taking its letters in order and repeating them as needed to reach exactly four characters
- Last two characters: a random two-digit number
Expected Output
// case 1
Enter your first and last name: Soham Parekh
Your username is: sparekh42
// case 2
Enter your first and last name: Ria Da
Your username is: rdada96
// case 3
Enter your first and last name: Mann Day
Your username is: mdayd17Q8.
Write a text-based DNA to RNA Converter that lets the user enter DNA sequences, validate them and then turns them into mRNA.
Instructions
- Prompt the user to enter a DNA sequence.
- Validate the input. (DNA sequence can contain only the letters A, T, C, G)
- Convert it to mRNA by replacing:
- T - A
- A - U
- C - G
- G - C
Expected Output
// case 1
Enter a DNA sequence: ATGCCAATT
Converted mRNA: UACGGUUAA
// case 2
Enter a DNA sequence: AGTX
Invalid DNA sequence! Please use only A, T, C and G.
Enter a DNA sequence: GGCC
Converted mRNA: CCGGQ9.
You and your friend want to send each other secret messages so that if anyone else sees the message data in between, they won’t understand it. To do this, you’ll write two programs:
- Encoder: turns your plain-text message into a string of numbers before one sends it.
- Decoder: takes that string of numbers and turns it back into the original text when one receives it.
Instructions
I. Encoder
Before sending a message, transform each character into its hidden numeric form. That way, anyone peeking at the data will see only numbers, not the secret words!
- Take the plain-text message as user input.
- For each character in the note, use
ord()to get its Unicode number. - Store those Unicode numbers and print the sequence of numbers.
II. Decoder
On receiving the secret code (a list of numbers), it needs to be turned back into the original message to be read easily by the recipient.
- Take the secret code as user input.
- For each number, use
chr()to convert it back to the character. - Join all characters into a single string and display the decoded message.
Expected Output
// Encoder
Enter your secret message: Club meeting at midnight in the treehouse!
Here is your encoded message:
67 108 117 98 32 109 101 101 116 105 110 103 32 97 116 32 109 105 100 110 105 103 104 116 32 105 110 32 116 104 101 32 116 114 101 101 104 111 117 115 101 33
// Decoder
Enter the secret code: 67 108 117 98 32 109 101 101 116 105 110 103 32 97 116 32 109 105 100 110 105 103 104 116 32 105 110 32 116 104 101 32 116 114 101 101 104 111 117 115 101 33
Your decoded message:
Club meeting at midnight in the treehouse!