start of day 2
This commit is contained in:
6
week 1/day 2/exo1.py
Normal file
6
week 1/day 2/exo1.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
number = input("please enter an number :")
|
||||||
|
|
||||||
|
if int(number) % 2:
|
||||||
|
print("Odd")
|
||||||
|
else:
|
||||||
|
print("Even")
|
||||||
0
week 1/day 2/exo2.py
Normal file
0
week 1/day 2/exo2.py
Normal file
19
week 1/day 2/exo3.py
Normal file
19
week 1/day 2/exo3.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name = input("please enter your name: ")
|
||||||
|
badChar = False
|
||||||
|
|
||||||
|
for ch in name:
|
||||||
|
if ch == ' ' or ( '0' <= ch <= '9'):
|
||||||
|
badChar = True
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
# verify if name less than 20 charachter, start with a letter and don't contain a bad Chararccer
|
||||||
|
|
||||||
|
first = name[0]
|
||||||
|
isLetter = ('A' <= first <= 'Z') or ( 'a' <= first <= 'z')
|
||||||
|
|
||||||
|
|
||||||
|
if(len(name) <= 20 and badChar == False and isLetter ):
|
||||||
|
print("Accepted")
|
||||||
|
else:
|
||||||
|
print("Refused")
|
||||||
55
week 1/day 2/readme.md
Normal file
55
week 1/day 2/readme.md
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# Day 2
|
||||||
|
|
||||||
|
## Exercises (Submit for Grading)
|
||||||
|
|
||||||
|
### Exercise 1 — Even / Odd
|
||||||
|
|
||||||
|
Ask for a number and print:
|
||||||
|
|
||||||
|
"Even" or "Odd"
|
||||||
|
|
||||||
|
use:
|
||||||
|
```python
|
||||||
|
n % 2
|
||||||
|
```
|
||||||
|
|
||||||
|
## Exercise 2 — Count Letters
|
||||||
|
|
||||||
|
Given a string:
|
||||||
|
|
||||||
|
count only alphabetic characters
|
||||||
|
|
||||||
|
ignore digits and symbols
|
||||||
|
|
||||||
|
## Exercise 3 — Rebuild Your C Validator (Python)
|
||||||
|
|
||||||
|
Write your own version (no copy-paste):
|
||||||
|
|
||||||
|
≤ 20 characters
|
||||||
|
|
||||||
|
starts with letter
|
||||||
|
|
||||||
|
no digits
|
||||||
|
|
||||||
|
no spaces
|
||||||
|
|
||||||
|
## Exercise 4 — Real-World Scenario
|
||||||
|
|
||||||
|
Given:
|
||||||
|
|
||||||
|
users = ["admin", "root1", "John_Doe", "Alice", "Bob42"]
|
||||||
|
|
||||||
|
Print only valid usernames.
|
||||||
|
|
||||||
|
Exercise 5 — Algorithm Explanation (Text)
|
||||||
|
|
||||||
|
Answer:
|
||||||
|
1. What happens to runtime if the list doubles in size?
|
||||||
|
|
||||||
|
2. Write the formula.
|
||||||
|
|
||||||
|
Expected:
|
||||||
|
|
||||||
|
T(n) = c × n
|
||||||
|
|
||||||
|
Explain in words.
|
||||||
Reference in New Issue
Block a user