-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnested_if.py
More file actions
120 lines (92 loc) · 3.34 KB
/
Copy pathnested_if.py
File metadata and controls
120 lines (92 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# int age = 25;
# bool hasLicense = true;
# bool hasID = true;
# if (age >= 18) {
# cout << "Age check passed" << endl;
# if (hasLicense) {
# cout << "Has license" << endl;
# if (hasID) {
# cout << "Has ID - Can drive!" << endl;
# } else {
# cout << "Needs ID" << endl;
# }
# } else {
# cout << "Needs license" << endl;
# }
# } else {
# cout << "Too young to drive" << endl;
# }
# in python
age = 25
has_license = True
has_id = True
if (age >= 18): # Level 1
print("Age check passed") # Level 1
if (has_license): # Level 2
print("Has license") # Level 2
if (has_id): # Level 3
print("Has ID - Can drive!") # Level 3
else: # Level 3
print("Needs ID") # Level 3
else: # Level 2
print("Needs license") # Level 2
else: # Level 1
print("Too young to drive") # Level 1
# c++
# #include <iostream>
# #include <string>
# using namespace std;
# int main() {
# string username, password;
# bool accountLocked = false;
# int loginAttempts = 0;
# cout << "Enter username: ";
# cin >> username;
# if (username == "admin") {
# cout << "Username found" << endl;
# cout << "Enter password: ";
# cin >> password;
# if (accountLocked) {
# cout << "Account is locked" << endl;
# } else {
# if (password == "admin123") {
# cout << "Login successful!" << endl;
# if (loginAttempts > 3) {
# cout << "Warning: Multiple failed attempts" << endl;
# }
# } else {
# cout << "Incorrect password" << endl;
# loginAttempts++;
# if (loginAttempts >= 5) {
# cout << "Account locked due to too many attempts" << endl;
# accountLocked = true;
# }
# }
# }
# } else {
# cout << "Username not found" << endl;
# }
# return 0;
# }
# in python
username = input("Enter username: ")
password = input("Enter password: ")
account_locked = False
login_attempts = 0
if username == "admin": # Level 1
print("Username found") # Level 1
if account_locked: # Level 2
print("Account is locked") # Level 2
else: # Level 2
if password == "admin123": # Level 3
print("Login successful!") # Level 3
if login_attempts > 3: # Level 4
print("Warning: Multiple failed attempts") # Level 4
else: # Level 3
print("Incorrect password") # Level 3
login_attempts += 1 # Level 3
if login_attempts >= 5: # Level 4
print("Account locked due to too many attempts") # Level 4
account_locked = True # Level 4
else: # Level 1
print("Username not found") # Level 1