Python 4.1 traverse the entire list (try it out)

Source: Internet
Author: User

4-1 Pizza:Think of at least three of your favorite pizzas, store their names in a list, and use the For loop to print out the name of each pizza.

    • Modify the For loop so that it prints a sentence that contains the name of the pizza, not just the name of the pizza. For each pizza, a line of output, such as "I like pepperoni pizza", is displayed.
      Pizzas = [' cheese pizza ', ' Durian pizza ', ' seafood pizza ']
      For pizza in Pizzas:
      (space) print ("I like" + Pizza.title ())

      • Add a line of code at the end of the program that doesn't indicate how much you like pizza in the For loop. The output should contain messages for each pizza and a concluding sentence, such as: "I really love pizza!" ”。
        Pizzas = [' cheese pizza ', ' Durian pizza ', ' seafood pizza ']
        For pizza in Pizzas:
        (space) print ("I like" + Pizza.title ())
        Print (I really love pizza!)

4-2 Animals: Think of at least three species of animals with common characteristics, store the names of these animals in a list, and then use the For loop to print out the names of each animal.

    • Modify the program so that it prints a sentence for each animal, such as "a dog would make a great pet!"
      Animals = [' dog ', ' cat ', Rabbit ']
      For animal in animals:
      (space) print ("a" + animal.title () "+" would make A great pet ")
    • Add a line of code at the end of the program to indicate what these animals have in common, such as printing "any of these animals would make a great pet!"
      Animals = [' dog ', ' cat ', Rabbit ']
      For animal in animals:
      (space) print ("a" + animal.title () "+" would make A great pet ")
      Print ("Any of these animals would make a great pet!")

Python 4.1 traverse the entire list (try it out)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.