Skip to content

Pen & PC

penandpc

Generate a Python list of all the even numbers between 4 to 30

January 15, 2023 by penandpc

You can use a for loop to generate a Python list of all the even numbers between 4 and 30. Here is one way you can write the code: This code uses a for loop to iterate through the range of numbers from 4 to 30. It checks whether the current number is even or … Read more

Categories Python Basic Programs Leave a comment

Python program to find smallest number in a list using for loop

January 15, 2023 by penandpc

Here’s a example code that demonstrates how to find the smallest number in a list using a for loop :- This program uses a for loop to iterate through the list of numbers, and compares each number to the current smallest value stored in the variable smallest. If the current number is smaller than the … Read more

Categories Python Basic Programs Leave a comment

python program to print min and max value in the list without using built-in function

January 14, 2023 by penandpc

Here is one way you can write a Python program to print the minimum and maximum value in a list without using any built-in functions: This program uses a for loop to iterate through the list of numbers, and compares each number to the current minimum and maximum values stored in the variables min_value and … Read more

Categories Python Basic Programs Leave a comment

Python program to find N largest elements from a list

January 14, 2023 by penandpc

You can use the heapq.nlargest() function from the heapq library to find the N largest elements from a list. Here’s an example: This will output [10, 9, 8] which are the 3 largest elements in the given list. You can also use the sorted() function in combination with slicing to get the same result: This … Read more

Categories Python Basic Programs Leave a comment

Second largest number in Python without sort

January 14, 2023 by penandpc

One way to find the second largest number in a list of numbers in Python without using the sort function is to use a combination of the max and min functions. First, you can use the max function to find the largest number in the list, and then use the min function to find the … Read more

Categories Python Basic Programs Leave a comment

Python program to find largest of 4 numbers using if else

January 13, 2023 by penandpc

In this program, the user is prompted to enter 4 numbers one by one. The program uses if-else statements to compare the numbers and find the largest one. It compares the first number with the second, third, and fourth numbers using if statement. If the first number is greater than the second, third and fourth … Read more

Categories Python Basic Programs Leave a comment

find the largest of n numbers using a user defined functions largest() in python

January 13, 2023 by penandpc

In the above python program to find the largest of n numbers using a user defined functions largest() we have defined a user defined function largest(n, nums) which takes two arguments, first one is the number of elements n and second is a list nums of numbers. Inside the function, I have initialized a variable … Read more

Categories Python Basic Programs Leave a comment

Python program to find largest of n numbers using for loop without list

January 13, 2023 by penandpc

In this tutorial, we will learn how to find the largest of n numbers using a for loop in Python. We will be using a simple approach that does not involve the use of lists. This method is great for beginners who are just starting to learn the basics of programming in Python. It is … Read more

Categories Python Basic Programs Leave a comment

Python program to find largest number in a list without max()

January 13, 2023 by penandpc

Here is a simple Python program that finds the largest number in a list without using the built-in max() function: This program defines a function find_largest() that takes in a list of numbers and finds the largest among them. The function initializes the variable largest to the first number and then iterates through the rest … Read more

Categories Python Basic Programs Leave a comment

write a simple python program to find the maximum of any number of numbers as defined by the user

January 13, 2023 by penandpc

In this article, we will write a simple Python program that allows the user to find the maximum of any number of numbers as defined by the user. The first step in writing this program is to create a function that takes a variable number of arguments. In Python, this can be done using the … Read more

Categories Python Basic Programs Leave a comment
Older posts
Page1 Page2 … Page5 Next →
© 2025 Pen & PC • Built with GeneratePress