codescracker


python

Python Programming Examples



« Python Tutorial Next Program »


Python Examples

To learn python practically, you must have to go through all the given python programs here. Practice these python programs to feel comfortable in python world.

Here you will see each and every python program from how to Print Hello World to Shutdown & Restart Computer using your python code. All python programs provided here along with their respective output.

Let's take a look at some python programs. Before going to all these python programs, first you have to setup your python environment to run all the python programs. Therefore, you can go for Python Environment Setup to learn how to setup python environment. But here, we have type and run all the programs just at Python IDLE, without saving any program. We recommend you to "save then run" each and every python program.

Python Program Example No.1

Here is the first python programming example:

# Python Program - Example No.1 
		
while True:
	print("Enter 'x' for exit.")
	val = input()
	if val == 'x':
		break
	else:
		print("Welcome to Python from codescracker.com!")
		print();

Here is the sample run of the first python programming example:

python programming examples

Python Program Example No.2

Here is the second python programming example:

# Python Program - Example No.2
		
while True:
	print("Enter 'x' for exit.")
	val = input()
	if val == 'x':
		break
	else:
		print("Hello,",val,"Sir, You are at codescracker.com\n")

Here is the sample run of the second python programming example:

python examples

Python Program Example No.3

Here is the third python programming example:

# Python Program - Example No.3
		
while True:
	print("Enter '0' for exit.")
	val = int(input("Guess a Number: "))
	if val == 0:
		break
	elif(val>10 and val<100):
		print("What a guess..!!\n")
	else:
		print("Opps..!!\n")

Here is the sample run of the third python programming example:

python programs examples with output

Python Program Example No.4

Here is the fourth python programming example:

# Python Program - Example No.4
		
while True:
	print("Enter 'x' for exit.")
	check = input("Are you a Robot ? ")
	if check == 'x':
		break
	elif(check == 'yes'):
		print("Sorry!, you can not proceed.\n")
	else:
		print("Congrats!, you can proceed.\n")

Here is the sample run of the fourth python programming example:

python examples with output

Programming Examples in Other Languages

You may also like to learn or practice programming examples in other popular programming languages:


« Python Tutorial Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test