0% found this document useful (0 votes)
3 views4 pages

Python Code

The document contains a series of Python code snippets demonstrating various programming concepts such as loops, conditionals, string manipulation, and recursion. Each snippet performs different tasks, including printing specific outputs based on conditions, calculating sums, and generating patterns. Overall, the document serves as a collection of coding examples for educational purposes.

Uploaded by

puhazh03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Python Code

The document contains a series of Python code snippets demonstrating various programming concepts such as loops, conditionals, string manipulation, and recursion. Each snippet performs different tasks, including printing specific outputs based on conditions, calculating sums, and generating patterns. Overall, the document serves as a collection of coding examples for educational purposes.

Uploaded by

puhazh03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CODE HUNT

1. def sympo(n):
if n <= 0:
print("Invalid input")
return

i=3
while i <= n:
if i % 12 == 0:
print("2024")
elif i % 4 == 0:
print("cse")
elif i % 2 == 0:
print("sparzo")
else:
print("welcome to our symposium")
i *= 2
n = 15
sympo(n)

2. nums = [10, 20, 30, 40, 50]


indices = [4, 3, 2, 1, 0]
result = 0
for i in range(0, 5, 2):
result += nums[indices[i]]
print(result // 9)

3. def strange_string(s):
result = []
for i, char in enumerate(s):
if i % 6 == 0:
result.append(char.upper())
else:
result.append(char.lower())
return ''.join(result)

input_str = "RATAN TATA"


output_str = strange_string(input_str)
print(output_str)

4. x = 10
y = (x := x + 1) + (x := x + 1)
print(y)

5. chars = ['S', 'p', 'a', 'r', 'z', 'o']


n=6
for i in range(1, n + 1):
for space in range(n - i):
print(" ", end="")
for j in range(i):
print(chars[j], end=" ")

print()

6. def main():
x = 10
y=5
x=x^y
y=x^y
x=x^y
print(x ^ y)
main()
7.def mystery_sum(arr):
sum = 0
for i in range(len(arr))
if i % 2 == 0:
sum+= arr[i]
else:
sum-= arr[i]
return sum
arr = [10, 5, 20, 15, 30, 25]
result = mystery_sum(arr[:5])
print(f"Result: {result}")

8. def mystery(n):
if n == 0:
return 0
return n + mystery(n - 1)
m=mystery(5)
print(m)

9. def mystery(n):
if n == 0:
return 0
return n + mystery(n - 1)
m=mystery(5)
print(m)

10. n = 4
for i in range(1, n):
for j in range(1, n):
if j == n - 1:
print("E", end="")
elif i * j == i:
print("G", end="")
else:
print("C", end="")
print()

You might also like