word="ayman" a="*" c="h" d="i" n=0 m=0 while n<10: n=n+1 print(c,end='') print(d,end='') print(a,end='') for b in word: print(b,end='') print(a) m=0 print(c,end='') while m<=n: print(d,end='') m=m+1 while n>=0: n=n-1 print(a,end='') for b in word: print(b,end='') print(a) m=0 print(c,end='') while m<n: m=m+1 print(d,end='') print(d,end='')
Wednesday, 11 February 2015
printing triangle pattern
Monday, 2 February 2015
python 3.4.2 part 13 write and read a text file
First create file "readwritefile.py"
/****************************/
/****************************/
fw=open("sample.txt","w")fw.write("i like to swim")fw.close()fr=open("sample.txt","r")textcontent=fr.read()print(textcontent)fr.close()
/*********************/
1.fw is variable, it just indicate file write, you can have your own variable
2.fr is variable, it just indicate file read, you can have your own variable
3.open("sample.txt","w"). it create a text file named "sample.txt"
4.and the attribute "w" , w is predefined attribute indicating writing permission
5.and the attribute "r" , w is predefined attribute indicating reading permission
6.close() is used to avoid wastage of memory
python 3.4.2 part 12 downlaoding an image
First install beautifulscraper
pip install beautifulscraper
create a new file downimage.py
/******************************/
import urllib.requestimport randomdef download_image(url):file_name=random.randrange(1,1000)full_file_name=str(file_name)+".jpg"urllib.request.urlretrieve(url,full_file_name)download_image("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7r5YcS7A_m8OAUsgT7W9M7HUm0vR7BD1Sv2jNnbgaP0tlPpuogQjzQeqlsQK0BRK3YMc4pLWl6m3_JJ_DrvjdUBfLCtkvOv0YFlkLjmB4xTcxLr_cn1uSPsXPPM71e50uf9gQGU3FrvY/s1600/2.jpg")
/***************************************/
run it 1.random is used select a random number
2.first we create download_image(url) function
3.to give a name for downloaded image, we use random function
4.str(file_name) is used to convert "file_name( number )" to string
5.urllib.request.urlretrieve is a function used to download the image
6."https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7r5YcS7A_m8OAUsgT7W9M7HUm0vR7BD1Sv2jNnbgaP0tlPpuogQjzQeqlsQK0BRK3YMc4pLWl6m3_JJ_DrvjdUBfLCtkvOv0YFlkLjmB4xTcxLr_cn1uSPsXPPM71e50uf9gQGU3FrvY/s1600/2.jpg" this url will pass to def download_image(url):
python 3.4.2 part 11 executing a function from other fileStudent code
Sunday, 1 February 2015
Friday, 30 January 2015
Monday, 26 January 2015
python 3.4.2 part 7 installing pip tutorial
https://pip.pypa.io/en/latest/installing.html
----->
https://bootstrap.pypa.io/get-pip.py
now open downloaded get-pip.py
now it will start installing
then goto
Control Panel\System and Security\System---->advanced system setting-->
environment variable-->
----->
https://bootstrap.pypa.io/get-pip.py
now open downloaded get-pip.py
now it will start installing
then goto
Control Panel\System and Security\System---->advanced system setting-->
environment variable-->
now open command prompt
Sunday, 25 January 2015
Python 3.4.2 Part 5 Using input tutorial
>>> x=input("Enter a string")
Enter a string ayman
>>> x
' ayman'
>>> y=input("Enter your name: ")
Enter your name: Ayman
>>> x
' ayman'
>>> y
'Ayman'
>>> x=input("Enter a string")
Enter a string5
>>> x
'5'
>>> y=int(input("Enter a number"))
Enter a number8
>>> y
8
>>> y+int(x)
13
Enter a string ayman
>>> x
' ayman'
>>> y=input("Enter your name: ")
Enter your name: Ayman
>>> x
' ayman'
>>> y
'Ayman'
>>> x=input("Enter a string")
Enter a string5
>>> x
'5'
>>> y=int(input("Enter a number"))
Enter a number8
>>> y
8
>>> y+int(x)
13
Now why we got an error in y+x??
please comment the reason
please comment the reason
Python 3.4.2 part1 installation tutorial
1.Goto this https://www.python.org/downloads/ site and download python 3.4.2 or for windows click this
https://www.python.org/ftp/python/3.4.2/python-3.4.2.msi
2.Install it
https://www.python.org/ftp/python/3.4.2/python-3.4.2.msi
2.Install it
Subscribe to:
Posts (Atom)