Python Assignment:
Print a list of four animals. Number the list without using the numbers 1,2,3,4. Use only the number 9 in your program to print 1,2,3,4.
Example Output:
Four cool animals:
1 donkey 2 monkey 3 lion 4 turkey
Thanks for Asking!
There can be multiple solutions to this:
Either we can directly print the list and numbers or a better way is by using these two lists:
One for numbering and One for names of animals.
a=["donkey","monkey","dog","turkey"]
b=[9/9 , 9/9+9/9 , 9/9+9/9+9/9, 9/9+9/9+9/9+9/9 ]
for i,j in zip(b,a):
print(int(i),j)
Output:
Hope you like it!
Sure! Here's an example program in Python that prints a list of four animals using the number 9 to represent the numbers 1, 2, 3, and 4:
pythonCopy codeanimals = ['Lion', 'Elephant', 'Tiger', 'Giraffe']for i, animal in enumerate(animals): print('Animal', i + 9, ':', animal)
Output:
yamlCopy codeAnimal 9 : LionAnimal 10 : ElephantAnimal 11 : TigerAnimal 12 : Giraffe
In this program, the enumerate()
function is used to iterate over the animals
list and retrieve both the index (i
) and the animal name (animal
). The index is then incremented by 9 to represent the numbers 1, 2, 3, and 4. The program prints each animal along with its corresponding number.
Python Assignment: Print a list of four animals. Number the list without using the numbers 1,2,3,4....
In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...
Define a function that creates a list of all the numbers that are factors of the user's number. For example, if the function is called factor, factor(36) should return [1, 2, 3, 4, 6, 9, 12, 18, 36]. The numbers in your list should be sorted from least to greatest, and 1 and the original number should be included. Remember to consider negative numbers as well as 0. Bonus: Have the program print the factors of the users number in...
python language
Problem Description: In this program we are going to explore a list or an array of integers using Python. Your program should read a set of integers from the user and store them in a list. Read numbers from the user until the user enters 0 to quit. Then store them in a list. Your program should them compute the sum of all the numbers in the list and output to the user. You will use lists and...
Python HELP How can a get the diagonals of an n x n list without using numpy. For example if have a list: L = [[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Then I can get the diagonals: 1, 6, 11, 16 2, 7 , 12 3, 8 5 , 10 ,15 9, 14 2, 5 3, 6, 9 4, 7, 10, 13 8, 11, 14 12,...
Python HELP How can a get the diagonals of an n x n list without using numpy. For example if have a list: L = [[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Then I can get the diagonals: 1, 6, 11, 16 2, 7 , 12 3, 8 5 , 10 ,15 9, 14 2, 5 3, 6, 9 4, 7, 10, 13 8, 11, 14 12,...
CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...
python
In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display the number n, the list of numbers, and a sub list of all the numbers in the list that are greater than the number n. Initialize the list and the number n in the main function of your code and call your function, passing the list and number as arguments. Run your code...
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...
PYTHON Ask the user for an integer number n. Construct, using one single loop, the list with the values [1,2,3,4,…,n] and the list with the values [1^2 ,2^2 ,3^2 ,…n^2 ] by using list concatenation ). After this loop is over, use a separate loop to show the user the two results by printing corresponding elements from the two lists in the same line, as follows: 1 1 2 4 3 9 … …
I want this using while loop
This using stringin python
Use list or some thing in python
Using list in python
I want answer as soon as posdible
E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...