0% found this document useful (0 votes)
21 views6 pages

Python Programming Assignments Guide

Here are the functions to help Chandler with currency exchange calculations: # Calculate number of whole bills def whole_bills(budget, denomination): return int(budget / denomination) # Calculate the value of bills def bills_value(denomination, number_of_bills): return denomination * number_of_bills # Calculate value after exchange def exchangeable_value(budget, denomination, exchange_rate, spread): spread_decimal = spread/100 exchange_rate += exchange_rate * spread_decimal return int(budget * exchange_rate // denomination) * denomination

Uploaded by

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

Python Programming Assignments Guide

Here are the functions to help Chandler with currency exchange calculations: # Calculate number of whole bills def whole_bills(budget, denomination): return int(budget / denomination) # Calculate the value of bills def bills_value(denomination, number_of_bills): return denomination * number_of_bills # Calculate value after exchange def exchangeable_value(budget, denomination, exchange_rate, spread): spread_decimal = spread/100 exchange_rate += exchange_rate * spread_decimal return int(budget * exchange_rate // denomination) * denomination

Uploaded by

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

Assignment on Python

I. Write the following python programs


a) To find the sum of square root of any three numbers.

b) To find the sum of first 100 integers.

c) To find the sum of all odd numbers till 100.

d) To find the sum of any five integers.

e) To find the factorial of number n.

f) To find the first n numbers in a Fibonacci series.

g) To find the sum of digits of a number.

h) To find whether a number is prime or not.

i) To convert temperature from Fahrenheit to Celsius

j) To solve the quadratic equation.

k) To find sum first 100 natural numbers.

l) To find factorial of a number.


m) Test whether a given year is leap year or not

II. Problems
Meltdown Mitigation
Problem Specification
This exercise contains information on developing a simple control system for a nuclear
reactor.

For a reactor to produce the power it must be in a state of criticality. If the reactor is in a
state less than criticality, it can become damaged, and if it goes beyond criticality, it can
overload and result in a meltdown.

We want to mitigate the chances of meltdown and correctly manage reactor state.

Tasks
Check for criticality

The first thing a control system has to do is check if the reactor is balanced in criticality.
A reactor is said to be critical if it satisfies the following conditions:

 The temperature is less than 800 K.


 The number of neutrons emitted per second is greater than 500.
 The product of temperature and neutrons emitted per second is less than
500000.

Implement a function is_criticality_balanced() that takes temperature (in Kelvin)


and neutrons_emitted as parameters, and returns true if the criticality conditions are
met, false if not.

Determine the Power output range

Once the reactor has started producing power its efficiency needs to be determined.
Efficiency can be grouped into 4 bands:

1. green -> efficiency of 80% or more,


2. orange -> efficiency of less than 80% but at least 60%,
3. red -> efficiency below 60%, but still 30% or more,
4. black -> less than 30% efficient.

The power generated ( generated_power ) can be calculated as voltage * current . And


the percentage value can be calculated as (generated_power /
theoretical_max_power) * 100 .

Implement the function reactor_efficiency() , which takes three parameters:

1. voltage
2. current
3. theoretical_max_power

and returns the efficiency band.

Fail Safe Mechanism

Your final task involves creating a fail-safe mechanism to avoid overload and meltdown.
This mechanism will determine if the reactor is below, at, or above the ideal criticality
threshold.
The reactor’s state can be determined by temperature*neutrons_produced_per_second .
Criticality can then be increased, decreased, or stopped by inserting or removing control
rods into the reactor.

 If the reactor’s state < 90% of threshold , output status code ‘LOW’, indicating
that control rods must be removed to produce power.
 If the reactor’s state is within plus or minus 10% of threshold , output status code
‘NORMAL’, indicating that the reactor is in optimum condition and control rods
are in an ideal position.
 If if it’s not in the above ranges, the reactor is going into meltdown and a status
code of ‘DANGER’ must be passed so that it can be shut down immediately.

Implement the function called fail_safe() , which takes 3 parameters:

1. temperature ,
2. neutrons_produced_per_second
3. threshold

and outputs a status code for the reactor.

Currency Exchange
Problem Specification
Your friend Chandler plans to visit tourist destinations across the United States. Sadly,
Chandler’s math skills aren’t good and he’s pretty worried about being finessed by
currency exchange booths during his trip. He’s discussing the travel plan with you and
wants your help with currency calculations.

During the discussion, you both learn that exchange booths dont deal with fractional
amounts.

Tasks
Chandler will need to exchange Euros for USDs. These are the tasks:

Calculate number of whole bills

Create function whole_bills() that takes the following parameters:


1. budget : The amount of money, in Euros, you are planning to exchange.
2. denomination : The value of a single bill.

and returns an integer corresponding to the number of bills, in USD, that fits into the
amount of Euros budgeted. Assume that 1 Euro = 1.05 USD.

Note: Round down to the nearest denomination (whole bill) as the exchange booth will
not return the fractional amount.

>>> whole_bills(127.5, 5)
25

Calculate the value of bills

Create function bills_value() that takes 2 parameters:

1. denomination : The value of a single bill.


2. number_of_bills : Amount of bills you received.

and returns the total value of the bills, in USD, the exchange booth will give back.

Note: The booth will not return the fractional amount.

>>> bills_value(5, 128)


640

Calculate value after exchange

Create function exchangeable_value() that takes the following parameters:

1. budget : The amount of money you are planning to exchange (in Euros).
2. denomination : The value of a single bill.
3. exchange_rate : The amount of domestic currency equal to one unit of foreign
currency (assume 1 Euro = 1.05 USD).
4. spread : The percentage taken by the exchange booth as a fee, written as an
integer.

This function should return the maximum value of the new currency (in integer), after
calculating the exchange rate plus the spread. Remember that the currency
denomination is a whole number.
Note: Spread needs to be converted to decimal by dividing it by 100.

Example: If 1.00 EUR = 1.05 USD and the spread is 10 , then the actual exchange rate will
be: 1.00 EUR == 1.155 USD because 10% of 1.05 is 0.105, which gets added as an
additional fee.

>>> exchangeable_value(127.25, 1.20, 10, 20)


80
>>> exchangeable_value(127.25, 1.20, 10, 5)
95

Common questions

Powered by AI

The number of whole bills is calculated using the function whole_bills() by taking the budget in Euros and the value of a single bill. The whole number of USD bills is determined by dividing the budget by the denomination and rounding down . Rounding down is applied because exchange booths do not deal with fractional amounts; they only provide whole bills, ensuring no leftover currency .

The criticality conditions for maintaining a nuclear reactor's safe operation include: (1) the temperature must be less than 800 K, (2) the number of neutrons emitted per second must be greater than 500, and (3) the product of temperature and neutrons emitted per second must be less than 500,000 . These conditions are crucial because they ensure that the reactor operates within safe limits to prevent damage due to under-criticality and avoid an overload that could lead to a meltdown.

In Python, a year can be verified as a leap year using conditional statements: a year is a leap year if it is divisible by 4, but not every year divisible by 100 unless it is also divisible by 400 . Programmatic verification is important to automate and accurately determine leap years, which is crucial for date calculations and calendar management in software applications.

The calculation of exchangeable value is crucial to determine the maximum amount of new currency after applying the exchange rate and booth fees. Factors influencing this include the budget in Euros, bill denomination, exchange rate, and spread. The exchange rate is adjusted by spreading, converting the fee percentage to a decimal, and adding it to the initial rate . This ensures accurate conversion accounting for costs applied by currency booths.

Solving a quadratic equation programmatically involves implementing the quadratic formula: roots are found using (-b ± sqrt(b²-4ac)) / (2a). Programmatic solutions allow handling of complex coefficients and automating calculations. Quadratic equations are significant as they model parabolic relationships in physics and engineering, appearing in diverse problem-solving contexts.

Managing the criticality of a nuclear reactor involves adjusting the state via control rods. The function fail_safe() determines the reactor’s state by multiplying temperature with neutrons produced per second . If the state is less than 90% of the threshold, the reactor status is 'LOW', indicating rods should be removed for power production. If within plus or minus 10% of threshold, the status is 'NORMAL', indicating optimal condition. Otherwise, the status is 'DANGER', requiring immediate shutdown to prevent meltdown .

Efficiency of a nuclear reactor is categorized into four bands: (1) "green" for an efficiency of 80% or more, (2) "orange" for an efficiency less than 80% but at least 60%, (3) "red" for an efficiency below 60%, but at least 30%, and (4) "black" for less than 30% efficiency . The efficiency percentage is calculated as (generated power / theoretical max power) * 100, where the generated power is the product of voltage and current .

Python can generate Fibonacci sequences using loops or recursion to compute each number as the sum of the two preceding ones, starting from 0 and 1 . Computational implications include handling of potentially large numbers and ensuring algorithm efficiency, as recursive methods may exhibit exponential time complexity, while iterative approaches are more performant for generating longer sequences.

Checking a number's primality is significant as it forms the basis for algorithms in cryptography and number theory applications. In Python, primality testing can be achieved using loops to check divisibility, where a number n is prime if it is only divisible by 1 and itself . Efficient primality testing ensures performance and security in various computational contexts.

Key considerations for converting temperature from Fahrenheit to Celsius programmatically include using the correct formula: (Fahrenheit - 32) * 5/9 = Celsius. This conversion requires accurate floating-point operations to ensure precision . Understanding and applying this formula is critical for data processing in scientific and engineering applications where temperature data may be provided in varying units.

You might also like