-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_if_conditional.py
More file actions
41 lines (34 loc) · 803 Bytes
/
4_if_conditional.py
File metadata and controls
41 lines (34 loc) · 803 Bytes
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
# Basic If statement
x = 10
if x > 5:
print("x is greater than 5")
# If-else statement
y = 3
if y % 2 == 0:
print("y is even")
else:
print("y is odd")
# If-elif-else statement
z = 7
if z < 0:
print("z is negative")
elif z == 0:
print("z is zero")
else:
print("z is positive")
# Nested If statement
a = 15
if a > 10:
if a % 2 == 0:
print("a is greater than 10 and even")
else:
print("a is greater than 10 and odd")
# User login example with if conditionals
username = "user123"
password = "password123"
input_username = input("Enter username: ")
input_password = input("Enter password: ")
if input_username == username and input_password == password:
print("Login successful!")
else:
print("Invalid username or password. Please try again.")