0% found this document useful (0 votes)
23 views1 page

Simple Python Programs for Beginners

This document provides simple Python programs for beginners, including examples like printing 'Hello, world!', adding two numbers, checking if a number is even or odd, calculating factorial using a loop, and using list comprehension to generate squares. Each program is presented with its code snippet for easy understanding. These examples serve as a foundational introduction to basic Python programming concepts.

Uploaded by

Karim Khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

Simple Python Programs for Beginners

This document provides simple Python programs for beginners, including examples like printing 'Hello, world!', adding two numbers, checking if a number is even or odd, calculating factorial using a loop, and using list comprehension to generate squares. Each program is presented with its code snippet for easy understanding. These examples serve as a foundational introduction to basic Python programming concepts.

Uploaded by

Karim Khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Simple Python Programs for Beginners

1. Hello World: print('Hello, world!')

2. Add Two Numbers: a = 5 b = 3 print(a + b)

3. Check Even or Odd: num = int(input('Enter number: ')) if num % 2 == 0: print('Even') else:
print('Odd')

4. Factorial Using Loop: def factorial(n): result = 1 for i in range(2, n+1): result *= i return result

5. List Comprehension: squares = [x*x for x in range(10)] print(squares)

You might also like