Write a python program to input a list of integer numbers from user an...
**Python program to find square of even numbers and cube of odd numbers in a list**
In this program, we will take a list of integers from the user and find the square of even numbers and the cube of odd numbers.
**Step-by-step approach:**
1. First, we will take input from the user for the list of integers.
2. Then, we will create an empty list to store the result of the square of even numbers and the cube of odd numbers.
3. Next, we will iterate through each element of the list.
4. If the number is even, we will find its square and append it to the result list.
5. If the number is odd, we will find its cube and append it to the result list.
6. Finally, we will print the result list.
**Python code:**
```python
# take input from user for list of integers
lst = list(map(int, input("Enter a list of integers: ").split()))
# create an empty list to store result
result = []
# iterate through each element of the list
for num in lst:
# if number is even, find its square and append to result list
if num % 2 == 0:
result.append(num ** 2)
# if number is odd, find its cube and append to result list
else:
result.append(num ** 3)
# print the result list
print("Result:", result)
```
**Output:**
```
Enter a list of integers: 1 2 3 4 5
Result: [1, 4, 27, 16, 125]
```
In the above example, we have taken a list of integers from the user as input and found the square of even numbers and the cube of odd numbers. The result is stored in the `result` list and printed at the end.
Write a python program to input a list of integer numbers from user an...
# Python program to input a list of integer numbers from user and finding square of even numbers and cube of odd numbers
#Entering a list from user
list1=eval(input("Enter a list of numbers:"))
#Creating an empty list for even and odd numbers
even=[ ]
odd=[ ]
for i in list1:
if i%2==0:
even.append(i)
else:
odd.append(i)
#Creating an empty list for sq of even and cube of odd
even_square=[ ]
odd_cube=[ ]
for j in even:
square=j**2
even_square.append(square)
for n in odd:
cube=n**3
odd_cube.append(cube)
#Displaying even no.& their squares and odd no.s and their cube
print("even numbers are:",even,"and their squares are",even_square)
print("odd numbers are:",odd,"and their cubes are:",odd_cube)
To make sure you are not studying endlessly, EduRev has designed Class 11 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 11.