8000 Added new exercises · codeguage-code/exercises@26e6d36 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26e6d36

Browse files
Added new exercises
1 parent 92409df commit 26e6d36

File tree

9 files changed

+91
-0
lines changed

9 files changed

+91
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Arithmetic Again Exercise
3+
4+
Read the exercise's description at [Python Foundation — Arithmetic Again Exercise](https://www.codeguage.com/courses/python/arithmetic-again-exercise).
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
while True:
2+
x = int(input('x: '))
3+
y = int(input('y: '))
4+
op = input('Operation: ')
5+
6+
if op == 'a':
7+
print('x + y =', x + y)
8+
elif op == 's':
9+
print('x - y =', x - y)
10+
elif op == 'm':
11+
print('x * y =', x * y)
12+
elif op == 'd':
13+
print('x / y =', x / y)
14+
elif op == 'e':
15+
print('x ** y =', x ** y)
16+
else:
17+
print('x % y =', x % y)
18+
19+
print() # blank line
20+
again = input('Restart? y for Yes, n for No.\n')
21+
22+
if again == 'n':
23+
break
24+
25+
print() # another blank line
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Linear Search Exercise
3+
4+
Read the exercise's description at [Python Foundation — Linear Search Exercise](https://www.codeguage.com/courses/python/linear-search-exercise).
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def linear_search(arr, target):
2+
for item in arr:
3+
if item == target:
4+
return True
5+
6+
return False
7+
8+
9+
# Test the function
10+
print(linear_search([1, 2, 3], 2))
11+
print(linear_search([1, 2, 3], '2'))
12+
print(linear_search(['2', '4', '6'], '2'))
13+
print(linear_search(['2, 6', '1, 4'], '2'))
14+
print(linear_search([False, False, False, True], False))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Palindromes Exercise
3+
4+
Read the exercise's description at [Python Foundation — Palindromes Exercise](https://www.codeguage.com/courses/python/palindromes-exercise).
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def is_palindrome(s):
2+
n = len(s)
3+
for i in range(n // 2):
4+
if s[i] != s[n - i - 1]:
5+
return False
6+
return True
7+
8+
9+
s = input('Enter a word: ')
10+
11+
if is_palindrome(s):
12+
print('Yes')
13+
else:
14+
print('No')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Any Number Exercise
3+
4+
Read the exercise's description at [Python Numbers — Any Number Exercise](https://www.codeguage.com/courses/python/numbers-any-number-exercise).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
x = input('x: ')
2+
y = input('y: ')
3+
4+
x = float(x)
5+
y = float(y)
6+
7+
if (x + y).is_integer():
8+
print('The sum is:', int(x + y))
9+
else:
10+
print('The sum is:', x + y)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
x = input('x: ')
2+
y = input('y: ')
3+
4+
x = float(x)
5+
y = float(y)
6+
7+
result = x + y
8+
9+
if result.is_integer():
10+
result = int(result)
11+
12+
print('The sum is:', result)

0 commit comments

Comments
 (0)
0