You are on page 1of 6

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

You might also like