-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path07_Practice.py
More file actions
83 lines (67 loc) · 1.66 KB
/
07_Practice.py
File metadata and controls
83 lines (67 loc) · 1.66 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# for loops
# Print each item in a shopping list
items =input("Enter items separated by commas: ").split(',')
for item in items:
print("Buy:",item.strip())
# Print squares of numbers from 1 to n
n = int(input("Enter a number:"))
for i in range(1,n+1):
print(i**2)
# while loops
# Countdown timer
time = int(input("Enter countdown time in seconds: "))
while time > 0:
print("Coundown left:",time)
time -= 1
# Sum until user enters 0
total = 0
num = int(input("Enter number (0 to stop): "))
while num != 0:
total += num
num = int(input("Enter number (0 to stop): "))
print("Total sum:",total)
# Print a multiplication table
n = 3
for i in range(1, 11):
print(f"{n} X {i} = {n*i}")
# Print Identity Matrix Pattern
n = 5
for i in range(n):
for j in range(n):
if i == j:
print("1", end=' ')
else:
print("0", end=' ')
print()
# Break
# Stop printing at a target item
items = ["apple", "banana", "cherry", "stop", "mango"]
for item in items:
if item == "stop":
break
print("Item:", item)
# Find first even number
while True:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("First even number found:", num)
break
# Continue
# Skip out-of-stock items
items = ["milk", "bread", "out of stock", "eggs"]
for item in items:
if item == "out of stock":
continue
print("Buy:", item)
# Skip even numbers
nums = 10
for i in range(1, nums+1):
if i%2==0:
continue
print(i,end=' ')
# pass
tasks = ["email", "meeting", "call"]
for task in tasks:
if task == "call":
pass # Logic to be added later
print("\nDo:", task)