-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1.py
More file actions
69 lines (56 loc) · 2.1 KB
/
lab1.py
File metadata and controls
69 lines (56 loc) · 2.1 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
# Lab:
# - write a program that prints hello world
print("hello world")
# - application to take a number in binary form from the user, and print it as a decimal
try:
binn = input(" Enter a binary number : ")
decimal = int(binn,2)
print("your binary number in decimal = " ,decimal)
except:
print("please inter a valid number")
# - write a function that takes a number as an argument and if the number
# divisible by 3 return "Fizz" and if it is divisible by 5 return "buzz" and if is is
# divisible by both return "FizzBuzz"
def validate_number(num):
if num %3 ==0 and num %5 ==0:
return "FizzBuzz"
elif num %3 ==0:
return "Fizz"
elif num % 5 == 0:
return "buzz"
else :
return "number you entered not divisible by 5 or 3 "
try:
num = int(input(" Enter number to check : "))
print(validate_number(num))
except:
print("Enter a numeric value ")
# - Ask the user to enter the radius of a circle print its calculated area and circumference
try:
radius = float(input("Enter the radius of circle : "))
Area = 3.14*radius**2
circumference = 2 * 3.14 * radius
print(f"the Area of your circle = {Area} and the circumference = {circumference}")
except:
print("Enter a number")
# - Ask the user for his name then confirm that he has entered his name (not an empty string/integers). then proceed to ask him for his email and print all this data
try:
name = input("Enter your name: ")
if not name.strip() or name.isdigit():
print("Invalid name. Please enter a valid name.")
email = input("Enter your email: ")
print("Name: ", name)
print("Email: ", email)
except:
print("please enter a valid name")
# - Write a program that prints the number of times the substring 'iti' occurs in a string
counter = 0
try:
string = str(input("Enter a string to check the occarance of iti : "))
for i in range(len(string)-2):
sub = string[i:i+3]
if sub == "iti":
counter +=1
print(counter)
except:
print("string not valid")