Py28
# Program 78: Check Sorted
def main():
nums = list(map(int, input("Enter numbers: ").split()))
if nums == sorted(nums):
print("Sorted")
else:
print("Not sorted")
main()
Enter numbers: 1 2 3 4 5
Sorted
# Program 79: Matrix Sum
def main():
m = [[1,2],[3,4]]
total = 0
for row in m …
Read More
Py29
# Program 81: Count Positive
def main():
nums = list(map(int, input("Enter numbers: ").split()))
count = 0
for n in nums:
if n > 0:
count += 1
print("Positive count:", count)
main()
Enter numbers: 12 34 56 7
Positive count: 4
# Program 82: Count Negative
def main():
nums = list(map(int, input …
Read More
Py9
# Program 21: ASCII Value
def main():
ch = input("Enter character: ")
print("Character is:", ch)
value = ord(ch)
print("ASCII value is:", value)
main()
Enter character: f
Character is: f
ASCII value is: 102
# Program 22: Alphabet Check
def main():
ch = input("Enter character: ")
print("Checking...")
if ch.isalpha():
print("It …
Read More
Rube1
numbers = [10, 20, 30, 40]
total = 0
for num in numbers:
total += num # shorter and clean
print("Total:", total)
numbers = [1, 2, 3, 4, 5, 6]
count = 0
for num in numbers:
if num % 2 == 0:
count += 1
print("Even Count:", count)
numbers = [5, 25, 10, 15]
largest = numbers[0 …
Read More
Rube2
# Program : Reverse List
numbers = [1, 2, 3, 4]
reversed_list = numbers[::-1] # better method (doesn't change original)
print("Reversed:", reversed_list)
# Program : Multiply All Elements
numbers = [2, 3, 4]
result = 1
for num in numbers:
result *= num
print("Multiplication Result:", result)
Multiplication Result: 24
Read More
Rube3
# Program 2: Addition
def main():
a = 10
b = 20
print("First number:", a)
print("Second number:", b)
result = a + b
print("Sum is:", result)
main()
First number: 10
Second number: 20
Sum is: 30
# Program 3: Addition using input
def main():
a = int(input("Enter first number: "))
b = int(input …
Read More