-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubstrings & Numbers.py
41 lines (36 loc) · 1.07 KB
/
Substrings & Numbers.py
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
#Sub_String
substring_1 = input("Enter substring")
substring_2 = input("Enter other substring")
substring_1 = sorted(substring_1)
substring_2 = sorted(substring_2)
if substring_1 == substring_2:
print("This is a substring")
else:
print("This is no string")
#Multiples"FIZZBUZZ"
for numbers in range(1,101):
if numbers % 3 == 0 and numbers % 5 == 0:
print("FizzBuzz")
if numbers % 3 == 0:
print("Fizz")
else:
print(numbers)
if numbers % 5 == 0:
print("Buzz")
else:
print(numbers)
#OtherNumber
def myevens(upper_limit):
even_sum = 0
for num in range(2, upper_limit + 1, 2):
even_sum += num
return even_sum
try:
user_input = int(input("Enter the upper limit: "))
if user_input < 1:
print("Please enter a positive integer greater than 0.")
else:
result = myevens(user_input)
print(f"Sum of even numbers between 1 and {user_input}: {result}")
except ValueError:
print("Invalid input. Please enter a valid positive integer.")