Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 922d8f2

Browse filesBrowse files
Added exercises
0 parents  commit 922d8f2
Copy full SHA for 922d8f2

File tree

Expand file treeCollapse file tree

26 files changed

+239
-0
lines changed
Filter options
Expand file treeCollapse file tree

26 files changed

+239
-0
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Addition Calculator Exercise
3+
4+
Read the exercise's description at [Python Foundation — Addition Calculator Exercise](https://www.codeguage.com/courses/python/addition-calculator-exercise).
+10Lines 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+
# convert x to int
5+
x = int(x)
6+
7+
# convert y to int
8+
y = int(y)
9+
10+
print('The sum is:', x + y)
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Clean Naming Exercise
3+
4+
Read the exercise's description at [Python Foundation — Clean Naming Exercise](https://www.codeguage.com/courses/python/clean-naming-exercise).

‎01-Foundation/2-Clean-Naming/code.py

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Name of the course.
2+
course_name = 'Python'
3+
4+
# Description of the course.
5+
course_desc = 'A general-purpose programming language'
6+
7+
# The difficulty level of the course.
8+
# A number in the range 1-10
9+
course_diff_level = 7
10+
11+
# The number of modules in the course.
12+
course_modules = 11
13+
14+
# The number of chapters in the course.
15+
course_chaps = 56
16+
17+
# The number of quizzes in the course.
18+
course_quizzes = 16
19+
20+
# The number of exercises in the course.
21+
course_exercises = 30
22+
23+
# The number of projects in the course.
24+
course_projects = 3
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Sorted Numbers Exercise
3+
4+
Read the exercise's description at [Python Foundation — Sorted Numbers Exercise](https://www.codeguage.com/courses/python/sorted-numbers-exercise).
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
x = int(input('x: '))
2+
y = int(input('y: '))
3+
z = int(input('z: '))
4+
5+
ints = [x, y, z]
6+
7+
# sort ints in ascending order
8+
ints.sort()
9+
10+
print('Sorted numbers:', ints[0], ints[1], ints[2])
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Rudimentary Calculator Exercise
3+
4+
Read the exercise's description at [Python Foundation — Rudimentary Calculator Exercise](https://www.codeguage.com/courses/python/rudimentary-calculator-exercise).
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
x = int(input('x: '))
2+
y = int(input('y: '))
3+
op = input('Operation: ')
4+
5+
# Blank line before output.
6+
print()
7+
8+
if op == 'a':
9+
print(x, '+', y, '=', x + y)
10+
elif op == 's':
11+
print(x, '-', y, '=', x - y)
12+
elif op == 'm':
13+
print(x, '*', y, '=', x * y)
14+
elif op == 'd':
15+
print(x, '/', y, '=', x / y)
16+
elif op == 'e':
17+
print(x, '**', y, '=', x ** y)
18+
elif op == 'r':
19+
print(x, '%', y, '=', x % y)
20+
else:
21+
print('Unknown operation.');
+4Lines 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).
+25Lines 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
+4Lines 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).

‎01-Foundation/6-Linear-Search/code.py

Copy file name to clipboard
+14Lines 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))

‎01-Foundation/7-Palindromes/README.md

Copy file name to clipboard
+4Lines 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).

‎01-Foundation/7-Palindromes/code.py

Copy file name to clipboard
+14Lines 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')

‎02-Numbers/1-Any-Number/README.md

Copy file name to clipboard
+4Lines 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).

‎02-Numbers/1-Any-Number/code.py

Copy file name to clipboard
+10Lines 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)
+12Lines 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)
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Multiplication Tables Exercise
3+
4+
Read the exercise's description at [Python Numbers — Multiplication Tables Exercise](https://www.codeguage.com/courses/python/numbers-multiplication-tables-exercise).
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
3+
n = random.randint(1, 10)
4+
print('The integer is:', n)
5+
6+
print()
7+
8+
for i in range(12):
9+
print(n, 'x', i + 1, '=', n * (i + 1))
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
3+
n = random.randint(1, 10)
4+
print('The integer is:', n)
5+
6+
print()
7+
8+
for i in range(1, 13):
9+
print(n, 'x', i, '=', n * i)
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Primes Below 10 Exercise
3+
4+
Read the exercise's description at [Python Numbers — Primes Below 10 Exercise](https://www.codeguage.com/courses/python/numbers-primes-below-10-exercise).
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import random
2+
3+
n = random.randint(1, 9)
4+
5+
if n == 2 or n == 3 or n == 5 or n == 7:
6+
print(n, 'is prime.')
7+
else:
8+
print(n, 'is NOT prime.')
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Abscissa and Ordinate Exercise
3+
4+
Read the exercise's description at [Python Strings — Abscissa and Ordinate Exercise](https://www.codeguage.com/courses/python/strings-abscissa-and-ordinate-exercise).
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
point = input('Enter the co-ordinate: ')
2+
3+
index = point.find(',')
4+
abscissa = point[1:index]
5+
ordinate = point[index + 1:-1]
6+
7+
print()
8+
print('Abscissa:', abscissa);
9+
print('Ordinate:', ordinate);
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Price After Discount Exercise
3+
4+
Read the exercise's description at [Python Strings — Price After Discount Exercise](https://www.codeguage.com/courses/python/strings-price-after-discount-exercise).
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
items = [(50, 30), (85, 10), (300, 15), (20, 5)]
2+
col_len = 20
3+
4+
print('Price'.ljust(col_len) + 'Discount'.ljust(col_len) + 'Price after discount'.ljust(col_len))
5+
print()
6+
7+
for item in items:
8+
price = item[0]
9+
discount = item[1]
10+
final_price = price - (price * discount / 100)
11+
12+
price = '${:.2f}'.format(price)
13+
final_price = '${:.2f}'.format(final_price)
14+
discount = str(discount) + '%'
15+
16+
print(price.ljust(col_len) + discount.ljust(col_len) + final_price.ljust(col_len))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.