What is the name of the user-defined function present in the following code snippet?*

import random
def test():
print("hello world")

randomNumber = random.randint(1, 10)
length = len("This is cool")
print(randomNumber, length)
test()
test
random
randint
len

The name of the user-defined function present in the code snippet is "test".

What does DRY stand for?*

Don’t Repeat Yourself
Do Repeat Yourself
Don’t Recall Yourself
Don’t Revise Yourself

DRY stands for "Don't Repeat Yourself".

What is the output of the following code snippet?*

def say_something():
print("I said something")
def print_something():
print("I printed something")
print_something()
I said something I printed something
I said something
I printed something
None of the options

The output of the following code snippet is:

"I printed something"

Which of the following built-in functions returns the length of a list?*


length()

min()

len()

max()

The built-in function that returns the length of a list is "len()".

Which of the following is not a relational operator?*

>=
!=
==
+=

The operator "+=" is not a relational operator. It is actually an assignment operator used for adding a value to a variable.

8. In the following code snippet, what should go in the ___ to loop through the `users` list?*

users = ["Daniel", "Ivann", "Natalie", "Kevin"]
for user in ___:
print(users)
user
users
list
None of the options

In the given code snippet, the correct answer to fill in the blank to loop through the `users` list would be `users`.

The correct code would be:
```python
users = ["Daniel", "Ivann", "Natalie", "Kevin"]
for user in users:
print(user)
```

Write a Python program based on these instructions:*

Create a `Funny Nickname` app.
This app should ask the user for their first name and then create a
nickname in the form "[nickname] [first_name]"
Hints:
- Import the function to choose a random item from a list.
- Create a list of at least 4 possible nicknames of your choosing.
- Prompt the user for their first name.
- Combine their first name with a random nickname from the nicknames list.
- Display their name/nickname with a message like: "What's up [nickname] [first_name]!"
- You should replace anything in [] with the value of the variables.

Sure! Here's a Python program that fulfills the given instructions:

```python
import random

def generate_nickname(first_name):
nicknames = ["FunnyGuru", "LaughingBuddy", "Jokester", "HilariousCraze"]

nickname = random.choice(nicknames)
full_name = f"{nickname} {first_name}"
return full_name

def main():
first_name = input("Enter your first name: ")
nickname = generate_nickname(first_name)
print(f"What's up {nickname}!")

if __name__ == "__main__":
main()
```

In this program, we create a function `generate_nickname()` that takes the `first_name` as input and randomly selects a nickname from the list `nicknames`. It then combines the nickname with the first name and returns the full name.

The `main()` function prompts the user for their first name, calls the `generate_nickname()` function to generate the nickname, and finally, prints the message with the nickname.

Write a Python program based on these instructions:*

Create a program that prompts a user to repeatedly guess a number.
Keep a tally of how many guesses it takes them to guess the number.
Once they guess the number, tell them how many guesses it took and end the program.
Hints:
- Generate a random number.
- You should use a function to do this so it's truly random
- Create a variable to track the `number_of_guesses`.
- Create an indefinite loop.
- Inside the loop:
- Prompt the user to guess the random number.
- If the user's guess is the same as the random number.
- Display a message saying: "That's correct, it took [number_of_guesses] for you to guess the number!"
- You should replace [number_of_guesses] with the value of the variable.
- Exit the loop.
- If the user's guess is NOT the same as the random number.
- Display a message saying: "Sorry, try again!".
- Add one to the `number_of_guesses`.

Certainly! Here's a Python program that fulfills the given instructions:

```python
import random

def guess_number():
random_number = random.randint(1, 100)
number_of_guesses = 0

while True:
user_guess = int(input("Guess the number: "))
number_of_guesses += 1

if user_guess == random_number:
print(f"That's correct! It took {number_of_guesses} guesses to find the number.")
break
else:
print("Sorry, try again!")

def main():
guess_number()

if __name__ == "__main__":
main()
```

In this program, we start by generating a random number within a range using the `random.randint()` function. We create a variable `number_of_guesses` to keep track of the number of guesses made by the user.

We then enter an indefinite loop and prompt the user to guess the number. If the user's guess is equal to the random number, we display a message indicating the correct guess and the number of guesses taken. We break out of the loop to end the program.

If the user's guess is not equal to the random number, we display a message to try again and increment the `number_of_guesses` variable. The loop continues until the user guesses the correct number.