Question 3.1: Write a Python function named "is_even" that takes an integer as input and returns True if the number is even, and False otherwise. Question 3.2: Write a Python function named "reverse_string" that takes a string as input and returns the reverse of the input string. Question 3.3: Write a Python function named "find_max" that takes a list of numbers as input and returns the maximum value from the list. Question 3.4: Write a Python function named "validate_password" that takes a string as input and checks if it is a valid password. A valid password should meet the following criteria: • It must be at least 8 characters long. • It must contain at least one uppercase letter, one lowercase letter, and one dig
时间: 2024-03-10 18:45:32 浏览: 206
Write-the-output-of-following-C-program1.zip_The Question
Answer 3.1:
Here is the Python function "is_even" that takes an integer as input and returns True if the number is even, and False otherwise:
```python
def is_even(num):
if num % 2 == 0:
return True
else:
return False
```
Answer 3.2:
Here is the Python function "reverse_string" that takes a string as input and returns the reverse of the input string:
```python
def reverse_string(input_str):
return input_str[::-1]
```
Answer 3.3:
Here is the Python function "find_max" that takes a list of numbers as input and returns the maximum value from the list:
```python
def find_max(nums):
max_num = nums[0]
for num in nums:
if num > max_num:
max_num = num
return max_num
```
Answer 3.4:
Here is the Python function "validate_password" that takes a string as input and checks if it is a valid password:
```python
def validate_password(password):
if len(password) < 8:
return False
has_uppercase = False
has_lowercase = False
has_digit = False
for char in password:
if char.isupper():
has_uppercase = True
elif char.islower():
has_lowercase = True
elif char.isdigit():
has_digit = True
if has_uppercase and has_lowercase and has_digit:
return True
else:
return False
```
阅读全文