-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_challenge.py
More file actions
59 lines (50 loc) · 1.77 KB
/
Copy path04_challenge.py
File metadata and controls
59 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
============================================
LECTURE 1 - FILE 4: BOSS CHALLENGE
Topics: ALL 6 Topics Combined
Total Challenges:
============================================
These problems test EVERYTHING you learned
in Lecture 1.
============================================
"""
# ==========================================
# CHALLENGE 1: The Smart Calculator (Easy-Medium)
# Topics Used: Variables, Data Types, Operators, Type Conversion
# ==========================================
"""
Write a program that:
1. Creates two variables: num1 = "15" and num2 = "4" (as STRINGS)
2. Converts both to integers
3. Performs ALL 7 arithmetic operations (+, -, *, /, //, %, **)
4. Stores each result in a separate variable with a valid identifier name
5. Prints each result in this exact format:
"15 + 4 = 19 (type: <class 'int'>)"
6. At the end, convert the sum to a boolean and print it.
"""
num1 = "15"
num2 = "4"
#covnert both string to interger
num1 =int("15")
num2 =int("4")
add = num1 + num2
sub = num1 - num2
multip = num1 * num2
divide = num1 / num2
floor_divide = num1 // num2
reminder = num1 % num2
power = num1 ** num2
print("15 + 4 = ",add,"type:",type(add))
print("15 - 4 = ",sub,"type:",type(sub))
print("15 * 4 = ",multip,"type:",type(multip))
print("15 / 4 = ",divide,"type:",type(divide))
print("15 // 4 = ",floor_divide,"type:",type(floor_divide))
print("15 % 4 = ",reminder,"type:",type(reminder))
print("15 ** 4 = ",power,"type:",type(power))
sum = bool(add)
print("sum as Boolean: ",sum)
#--------------------------------------------------------------------------------------
# ==========================================
# CHALLENGE 2: The Type Detective
# Topics Used: Data Types, Operators, Type Conversion, Identifiers
# ==========================================