You have a list of AI models. Print each one on its own line.
models = ["GPT-4", "Claude", "Gemini", "Llama", "Mistral"]Expected output:
GPT-4
Claude
Gemini
Llama
Mistral
Solution – Iteration 1
models = ["GPT-4", "Claude", "Gemini", "Llama", "Mistral"]
for model in models:
print(model)Now print each model with its position in the list (starting at 1).
Expected output:
1. GPT-4
2. Claude
3. Gemini
4. Llama
5. Mistral
Solution – Iteration 2
models = ["GPT-4", "Claude", "Gemini", "Llama", "Mistral"]
for i, model in enumerate(models):
print(f"{i + 1}. {model}")Count how many models have a name shorter than 6 characters, and print the result.
Solution – Bonus 1
models = ["GPT-4", "Claude", "Gemini", "Llama", "Mistral"]
count = 0
for model in models:
if len(model) < 6:
count += 1
print(f"Models with short names: {count}")Ask the user to enter a model name. Loop through the list and print "Found it!" if it matches, or "Not found." if it doesn't.
Solution – Bonus 2
models = ["GPT-4", "Claude", "Gemini", "Llama", "Mistral"]
search = input("Enter a model name: ")
for model in models:
if model == search:
print("Found it!")
break
else:
print("Not found.")