print('''
DATAIDEA
Sir Apollo Kagwa Road,
Kampala,
Uganda
-------------------
www.dataidea.org
''')
DATAIDEA
Sir Apollo Kagwa Road,
Kampala,
Uganda
-------------------
www.dataidea.org
Juma Shafara
August 12, 2024
python, quiz, python quiz, dataidea, data science
DATAIDEA
Sir Apollo Kagwa Road,
Kampala,
Uganda
-------------------
www.dataidea.org
DATAIDEA
Sir Apollo Kagwa Road,
Kampala,
Uganda
-------------------
www.dataidea.org
number = 34.5678
print('Nearest integer:', round(number))
print('2 decimal places:', round(number, 2))
Nearest integer: 35
2 decimal places: 34.57
number = int(input('Enter number: '))
if number % 2 == 0:
print('Number is even')
else:
print('Number is odd')
Number is even
Marks | Grade |
---|---|
>= 75 | A |
> 50 and <=75 | B |
> 25 and <=50 | C |
<= 25 | D |
marks = 56
if marks >= 75:
print('A')
elif marks > 50 and marks <= 75:
print('B')
elif marks > 25 and marks <= 50:
print('C')
else:
print('D')
B
# your solution
char = 'a'
# to lower
if char.isupper():
char = char.lower()
else:
char = char.upper()
print(char)
A
# your solution
amount_to_pay = float(input("Enter amount to pay: "))
if amount_to_pay >= 1000:
amount_to_pay = amount_to_pay * 0.95
print(amount_to_pay)
1140.0
# your solution
u = float(input("Enter the initial velocity (m/s): "))
v = float(input("Enter the final velocity (m/s): "))
t = float(input("Enter the time (s): "))
getAcceleration = lambda u, v, t: (v - u) / t
print("The acceleration is:", getAcceleration(u, v, t), "m/s^2")
The acceleration is: 1.0 m/s^2
c = 5( f − 32) / 9
# your solution
temperature_reading = input("Enter the temperature: ")
unit = str(temperature_reading[-1])
temperature_value = float(temperature_reading[:-1])
if unit.lower() == "c":
fahrenheit = (temperature_value * 9/5) + 32
print(f"{temperature_value}°C is equivalent to {round(fahrenheit, 3)}°F")
else:
celsius = (temperature_value - 32) * 5/9
print(f"{temperature_value}°F is equivalent to {round(celsius, 3)}°C")
10.0°F is equivalent to -12.222°C
Enter number 1: 20
Enter number 2: 12
Mathematical Operation
-----------------------------------
1 - Add
2 - Subtract
3 - Multiply
4 - Divide
-----------------------------------
Enter your preference: 2
Answer : 8.00
# your solution
# Develop a simple calculator to accept two floating point numbers from the keyboard.
# Then display a menu to the user and let him/her select a mathematical operation to be performed on
# those two numbers. Then display the answer.
number1 = int(input("Enter the number 1: "))
number2 = int(input("Enter the number 2: "))
operation = input(
'''
Mathematical Operation
-----------------------------------
1 - Add
2 - Subtract
3 - Multiply
4 - Divide
-----------------------------------
Enter your preference:
'''
)
operation_map = {
'1': number1 + number2,
'2': number1 - number2,
'3': number1 * number2,
'4': number1 / number2
}
print(f'Answer: {operation_map[operation]}')
Answer: 10
[100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200]
Sum: 7650
# your solution
# factorial
def getFactorial(n):
if n == 0:
return 1
else:
return getFactorial(n - 1) * n
print(getFactorial(5))
120
# your solution
def getSumBetween(start, end):
sum = 0
for counter in range(start, end+1):
sum += counter
return sum
print(getSumBetween(1, 10)) # 55
55
Before we continue, I have a humble request, to be among the first to hear about future updates of the course materials, simply enter your email below, follow us on (formally Twitter), or subscribe to our YouTube channel.
# your solution
def getSumBetween(start, end):
if start < 0 or end < 0:
print('Error: Start or end cannot be negative')
return -1
sum = 0
for i in range(start, end+1):
sum += i
return sum
print(getSumBetween(-2, 5))
Error: Start or end cannot be negative
-1
*
**
***
****
*****
******
# Write a program to store marks of 5 students for 5 subjects given through
# the keyboard. Calculate the average of each students marks and the average
# of marks taken by all the students
# your solution
student_marks = []
for i in range(5):
student_marks.append([])
for j in range(5):
mark = int(input(f"Enter marks for student {i+1}, subject {j+1}: "))
student_marks[i].append(mark)
for i in range(5):
student_average = sum(student_marks[i]) / len(student_marks[i])
print(f"Average marks for student {i+1}: {student_average:.2f}")
all_marks = []
for student in student_marks:
all_marks.extend(student)
overall_average = sum(all_marks) / len(all_marks)
print(f"Overall average of all students: {overall_average:.2f}")
Hello World!
This is my first file
Menu
-----------------------------------
1 – Microsoft Word
2 – Yahoo messenger
3 – AutoCAD
4 – Java Games
-----------------------------------
Enter number of your preference:
----------------Menu-------------------------
1. Add new friend.
2. Display contact info.
3. Exit
------------------------------------------------
Enter menu number:
When you press “1” it should request you to enter following data:
---------New friend info--------
Name : Saman
Phone-No: 011-2123456
e-Mail : saman@cse.mrt.ac.lk
After adding new contact information it should again display the menu. When you press “2” it should display all the contact information stored in the directory.txt file as follows:
--------------Contact info---------------
Name Tel-No e-Mail
Kamala 077-7123123 kamala@yahoo.com
Kalani 033-4100101 kalani@gmail.com
Saman 011-2123456 saman@cse.mrt.ac.lk
-----------------------------------------
(a) if m < 3
(b) let m = m + 12 and let y = y - 1
(c) let a = 2m + 6 (m + 1) / 10
(d) let b = y + y/4 – y/100 + y/400
(e) let f 1 = d + a + b + 1
(t) let f = f 1 mod 7
(g) stop.
Write a program that will read a date and print the corresponding day of the week. All divisions indicated above are integer divisions.
Enter 10 numbers: 5 7.8 9.6 54 3.4 1.2 3 7 8.8 5
Minimum = 1.2
Maximum = 54
Enter the marks of four students, on four rows:
50 60 80
60 75 90
30 49 99
66 58 67
Total marks of four students:
190
225
178
191
Congratulations on completing this Python Fundamentals Course