Python Programming for Beginners
Monday, 12 June 2017
Friday, 3 February 2017
Bubble Sort Program in Python
In bubble sorting first and second elements are compared if first one is greater than second one then both are exchanged, here below 25 is greater than 15 so their position is exchanged.
Then the second and third elements are compared but not like above case here 25 is not greater than 36 then nothing will happen here. and so on.
First Iteration
Bubble Sort Program in Python:
print 'Bubble Sorting'
print 'Enter the element of the list and write 'done/Done' to stop'
loop = True
list = []
while loop == True:
lis = raw_input()
if lis == 'done' or lis=='Done':
loop =False
else:
list.append(int(lis))
leng = len(list)
print leng
for i in range(0,leng):
for j in range(0,leng):
if j < leng-1:
if list[j] > list[j+1]:
a = list[j]
list[j] = list[j+1]
list[j+1]=a
print 'Sorted list will be',list
Friday, 30 September 2016
Game of Rock Paper Scissors in Python
Rock Paper Scissors (Python)
import random
lst = ['rock','paper','scissors']
print "\n\n Rock, Paper and Scissors \n\n"
print "\n You are playing vs Computer\n"
user = raw_input("Enter yr name:")
while(True):
user1 = raw_input("%s, do yo want to choose rock, paper or scissors?" % user)
if user1 not in lst:
print "Invalid Input(Please input exaclty words givne to choose)"
computer = random.choice(lst)
if user1 in lst:
print 'Computer chooses', computer
if computer == user1:
print 'Its a Tie'
if computer == 'rock' and user1 == 'paper':
print '\n\n%s Wins\n\n' %user
if computer == 'rock' and user1 == 'scissors':
print '\n\nComputer Wins\n\n'
if computer == 'paper' and user1 == 'rock':
print '\n\nComputer Wins\n\n'
if computer == 'paper' and user1 == 'scissors':
print '\n\n%s Wins\n\n' %user
if computer == 'scissors' and user1 == 'rock':
print '\n\n%s Wins\n\n' %user
if computer == 'scissors' and user1 == 'paper':
print '\n\nComputer Wins\n\n'
print 'Play again(yes/no)'
user_play_again = raw_input('\nEnter(yes or no):\n')
if user_play_again == 'yes':
continue
else:
print '\n\nGame Over\n\n'
break
OUTPUT:
import random
lst = ['rock','paper','scissors']
print "\n\n Rock, Paper and Scissors \n\n"
print "\n You are playing vs Computer\n"
user = raw_input("Enter yr name:")
while(True):
user1 = raw_input("%s, do yo want to choose rock, paper or scissors?" % user)
if user1 not in lst:
print "Invalid Input(Please input exaclty words givne to choose)"
computer = random.choice(lst)
if user1 in lst:
print 'Computer chooses', computer
if computer == user1:
print 'Its a Tie'
if computer == 'rock' and user1 == 'paper':
print '\n\n%s Wins\n\n' %user
if computer == 'rock' and user1 == 'scissors':
print '\n\nComputer Wins\n\n'
if computer == 'paper' and user1 == 'rock':
print '\n\nComputer Wins\n\n'
if computer == 'paper' and user1 == 'scissors':
print '\n\n%s Wins\n\n' %user
if computer == 'scissors' and user1 == 'rock':
print '\n\n%s Wins\n\n' %user
if computer == 'scissors' and user1 == 'paper':
print '\n\nComputer Wins\n\n'
print 'Play again(yes/no)'
user_play_again = raw_input('\nEnter(yes or no):\n')
if user_play_again == 'yes':
continue
else:
print '\n\nGame Over\n\n'
break
OUTPUT:
Monday, 26 September 2016
Thursday, 22 September 2016
How to install python 2.7 on windows???
Python Installation
1. First of all download the python version 2.7 from here here (Pythons 2.7 latest version is 2.7.12) .
2.Click on python 2.7.12
.exe file will download on your pc/laptop.
3. Click on the downloaded .exe file.
To be Cont.
Monday, 1 June 2015
Welcome to Python for Beginners...
Python for Beginners
Hello guyz this tutorial is for beginners who want to learn python.
- If you are new to programming world just learn python from very beginning.
- If you already done some language before python then you can skip some basic or common topics which are covered by every programming language.
- Basic Knowledge of HTML.
- Basic knowledge of css.
to learn HTML and CSS.
To be cont...
Subscribe to:
Posts (Atom)