Skip to content

Commit e276dcf

Browse files
Merge pull request #1 from PavanMudigondaTR/dev
Dev
2 parents 112b932 + 7929824 commit e276dcf

94 files changed

Lines changed: 642 additions & 86 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

0-examples/one.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print("Hello, World!")
2+

10-temp/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
unit = input("Enter the unit of temperature (F/C): ")
2+
3+
# In US temperate is measured in Fahrenheit F
4+
# In Canada temperature is measured in Centigrade/Celsius C
5+
26
temp = float(input("Enter the temperature: "))
7+
38
if unit == "F":
4-
temp = round(((temp - 32) * 5) / 9)
5-
print(f'The temperature in Fahrenheit is, {temp} {unit}')
9+
temp = (( temp - 32 ) * 5.0/9.0)
10+
print(f'The temperature in Fahrenheit is, {temp} C °')
611
elif unit == "C":
7-
temp = round(((temp * 9 ) / 5) + 32)
8-
print(f'The temperature in Celsius is, {temp} {unit}')
12+
temp = ( ( temp * 9.0/5.0 ) + 32 )
13+
print(f'The temperature in Celsius is, {temp} F ')

12-conditional/main.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
num = 5
22
a = 6
33
b = 7
4+
age = 13
5+
temperature = 22
6+
7+
user_role = 'admin'
8+
9+
print("positive" if num > 0 else "non-positive")
10+
result = 'EVEN' if num % 2 == 0 else 'ODD'
11+
print(result)
412

513
max_num = a if a > b else b
614
print(f'maximum number: {max_num}')
715
min_num = a if a < b else b
8-
print(f'minimum number: {min_num}')
16+
print(f'minimum number: {min_num}')
17+
18+
access_level = 'Full Access' if user_role == 'admin' else 'non-admin'

13-string/main.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name = input("Enter your name: ")
22

3+
4+
35
print("Hello, " + name + "!")
46

57
len = len(name)
@@ -23,9 +25,20 @@
2325

2426
print("The position of the letter 'P': " + str(find_p))
2527

26-
#result = name.isdigit()
28+
name = name.capitalize()
29+
30+
result = name.isdigit()
2731

2832
result = name.isnumeric()
2933

3034

31-
print("Is your name a number? " + str(result))
35+
36+
print("Is your name a number? " + str(result))
37+
38+
phone_number = input("what is your phone number ?")
39+
40+
phone_number = phone_number.replace('-',"")
41+
42+
print(phone_number)
43+
44+
print(help(str))

13-string/task.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# validate user input exercise
2+
3+
# 1. username is no more than 12 characters
4+
# 2. username must not contain spaces
5+
# 3. username must not contain digits
6+
7+
user_name = input("enter a username: ")
8+
if len(user_name) > 12:
9+
print("username can not be more than 12 characters")
10+
elif not user_name.find(" ") == -1:
11+
print("username can not contain a space")
12+
elif not user_name.isalpha():
13+
print("user name can not contain numerics")
14+
else:
15+
print(f"welcome {user_name}")

14-index/main.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1-
credit_card = '4111123456781234'
1+
# indexing = accessing elements of a sequence using [] (indexing operator)
2+
# [start : end : step]
23

3-
print(credit_card[0:4])
4+
credit_card = '4111-1234-5678-1234'
5+
6+
print(credit_card[0])
7+
8+
print(credit_card[2])
9+
10+
print(credit_card[0:4])
11+
12+
print(credit_card[0:4])
13+
14+
print(credit_card[5:9])
15+
16+
print(credit_card[5:])
17+
18+
print(credit_card[-1])
19+
20+
print(credit_card[::3])
21+
22+
print(credit_card[::-1])
23+
24+
print(f'')

15-format/main.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
# format specifers = {:flags} format a value based on what
2+
# flags are inserted
3+
4+
# :.2f → Round to 2 decimal places (fixed-point notation).
5+
# :10 → Allocate 10 spaces (default is right-aligned).
6+
# :>10 → Right justify within 10 spaces.
7+
# :<10 → Left justify within 10 spaces.
8+
# :^10 → Center align within 10 spaces.
9+
# :03 → Zero-pad to width 3.
10+
# :+ → Show + for positive numbers.
11+
# := → Place sign at the leftmost position.
12+
# : → Insert a space before positive numbers.
13+
# : , → Add comma as thousands separator.
14+
115
price1 = 3.234443
216
price2 = 4.234443
317
price3 = 5.234443
418
price4 = 1234567.234443
519

6-
print(f'Price 1: $ {price1:.2f}')
7-
print(f'Price 1 - right justified: $ {price1:>10}')
8-
print(f'Price 1 - left justified: $ {price1:<10}')
9-
10-
print(f'Price 1 - left justified: $ {price4: ,}')
11-
12-
print(f'Price 1 - left justified: $ {price4: ,.2f}')
20+
print(f'Price 1: $ {price1:.2f}') # $ 3.23 (rounded to 2 decimals)
21+
print(f'Price 1 - right justified: $ {price1:>10}') # spaces before number
22+
print(f'Price 1 - left justified: $ {price1:<10}') # spaces after number
23+
print(f'Price 4 with comma: $ {price4:,}') # $ 1,234,567.234443
24+
print(f'Price 4 with comma & 2 decimals: $ {price4:,.2f}') # $ 1,234,567.23

16-while/age.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# execute some code WHILE some condition remains true
12
age = int(input("Enter your age: "))
23

34
while age < 18:

16-while/food.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# execute some code WHILE some condition remains true
12
food = input("What is your favorite food? ")
23

34
while food != "q":

16-while/num.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
# execute some code WHILE some condition remains true
23
num = input("Enter a number between 1 and 10: ")
34

45
while int(num) < 1 or int(num) > 10:

0 commit comments

Comments
 (0)