What happens when a function is defined in python?
A function holds code, which means you can essentially 'store' code within the function, allowing it to be 'reused' or 'called' later on.
A string is a collection of words or characters in '' or "" it is also a data type.
How do you write hotel program in python?
# This program was authored by M. Srinu , RGU IIIT NUZVID.
# Please maintain certain indentation after copying the program.
from Tkinter import *
import Tkinter
import tkMessageBox
import Tkinter as tk
import os, glob
import sys
import string
import re
import tkFileDialog
import random
while(3):
def hotel():
print "\t\t\t//** Hi friend welcome to my new hotel**//\n"
n=raw_input("Enter your name here :")
class Application(Frame):
def say_hi(self):
print "Hi !",n
def createWidgets(self):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["bg"] ="yellow"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "left"})
self.hi_there = Button(self)
self.hi_there["text"] = "Hello",
self.hi_there["fg"] = "red"
self.hi_there["bg"] ="blue"
self.hi_there["command"] = self.say_hi
self.hi_there.pack({"side": "left"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
d={'idly':10,'dosa':15,'puri':15,'biryani':40,'chicken biryani':50,'rice':35,'yellow rice':30}
top = Tkinter.Tk()
def hello():
tkMessageBox.showinfo(" Menu","item\t Rs\n\nidly\t10\ndosa\t15\npuri\t15\nrice\t35\nbiryani\t40\nchicken biryani 50\nyellow rice 30\n\n'Note': Please close the below window after press the ok button.")
B1 = Tkinter.Button(top, text = "Press this button to see the menu", command = hello)
B1.pack()
top.mainloop()
l=[]
print ("Plz give order,if u enough just press 'Enter'\n")
while(1):
k=raw_input("Order which item u want >>>") #take order
if k=='':
break;
l.append(k) #take ordered items into a list
print("\t\t\tThanq for ur ordered\n")
class Application(Frame):
def say_hi(self):
print "Your ordered menu is",l
def createWidgets(self):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["bg"] ="yellow"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "left"})
self.hi_there = Button(self)
self.hi_there["text"] = "Your ordered menu",
self.hi_there["fg"] = "red"
self.hi_there["bg"] ="blue"
self.hi_there["command"] = self.say_hi
self.hi_there.pack({"side": "left"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
s=0
print "\t\t\t/**/Individual bill is/**/\t"
print"\t\t\t* * * * * * * * * * *"
print("\t\t\titem\t\tprice")
print"\t\t\t* * * * * * * * * * *"
for i in l: #to print the the ordered item and price
for key in d:
if i==key:
s+=d[key]
print "\t\t\t",i,"\t\t",d[i]
if i not in d:
print "\t\t\tThe item ",i," was not found in the menu"
print"\t\t\t* * * * * * * * * * *"
jk=raw_input("If u want to drink anything just press y >>>") #ask user he/she want to drink anything or not
if jk=="y":
q={'tea':5,'coffee':7,'ice-cream':10,'cone ice-cream':20,'coke':25,'pepsi':20,'mazza':25}
top = Tkinter.Tk()
def hello2():
tkMessageBox.showinfo(" Menu","item\t Rs\n\ntea\t05\ncoke\t25\ncoffee\t07\npepsi\t20\nmazza\t25\nice-cream\t10\ncone ice-cream 20\n\n'Note': Please close the below window after press the ok button.")
B2 = Tkinter.Button(top, text = "Press this button to see the menu", command = hello2)
B2.pack()
top.mainloop()
list=[]
print " if u enough just press 'Enter'\n"
while(2):
a=raw_input("Order which item u want >>>")
if a=='':
break;
list.append(a)
class Application(Frame):
def say_hi(self):
print "Your ordered menu is",list
def createWidgets(self):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["bg"] ="yellow"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "left"})
self.hi_there = Button(self)
self.hi_there["text"] = "Your ordered menu",
self.hi_there["fg"] = "red"
self.hi_there["bg"] ="blue"
self.hi_there["command"] = self.say_hi
self.hi_there.pack({"side": "left"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
b=0
print "\t\t\t/**/Individual bill is/**/\t"
print"\t\t\t* * * * * * * * * * *"
print("\t\t\titem\t\tprice")
print"\t\t\t* * * * * * * * * * *"
for i in list:
for key in q:
if i==key:
b+=q[key]
print "\t\t\t",i,"\t\t",q[i]
if i not in q:
print"\t\t\tThe item ",i," was not found in the menu"
print"\t\t\t* * * * * * * * * * *"
print "Total bill for your eating is ",s,"\n"
print "Total bill of your drinking is ",b,"\n"
print "Total bill of your drinking and eating is ",s+b,"\n"
def gift():
if s+b>=150:
box=['A.C','P.C','T.V','Refrigerator','Dining table']
random.shuffle(box)
l=input("WoW !!!! Congratulations @!!@ you got a lottery Enter which index item u want(0 to 4) >>>")
print "\nIn this lottery you got a",box[l],"\n We will sent this item to your home plz fill the below form \n"
print"\t\t*****************************\n\t\t* The lottery box items are *\n\t\t*****************************\t\t\n--------------------------------------------------------------------------\n",box,"\t\t\n--------------------------------------------------------------------------\n"
print"\t\t\t\t//**Lottery form**//"
name=raw_input("Enter your name here(What u gave first) >>>\n--------------\n")
while(n!=name):
name=raw_input("Please enter What u gave first) >>>\n--------------\n")
print("--------------")
p_n=input("Enter your phone number here >>>\n--------------\n")
print("--------------")
address=raw_input("Enter your address here in this form (vill,m.d,dist) >>>\n--------------\n")
print("--------------")
print"Thanq,",name," we will sent the","'",box[l],"'", "to your address\n"
elif s+b>=100:
box=['Cricket bat','Volley ball','video game','5-books','Bag','Radio']
random.shuffle(box)
l=input("WoW !!!! Congratulations @!!@ you got a lottery Enter which index item u want(0 to 5) >>>")
print "\nIn this lottery you got a",box[l],"\n We will sent this item to your home plz fill the below form \n"
print"\t\t*****************************\n\t\t* The lottery box items are *\n\t\t*****************************\t\t\n--------------------------------------------------------------------------\n",box,"\t\t\n--------------------------------------------------------------------------\n"
print"\t\t\t\t//**Lottery form**//"
name=raw_input("Enter your name here(What u gave first) >>>\n--------------\n")
while(n!=name):
name=raw_input("Please enter What u gave first) >>>\n--------------\n")
print("--------------")
p_n=input("Enter your phone number here >>>\n--------------\n")
print("--------------")
address=raw_input("Enter your address here in this form (vill,m.d,dist) >>>\n--------------\n")
print("--------------")
print"Thanq,",name," we will sent the","'",box[l],"'", "to your address\n"
elif s+b>=50:
box=['watch','camera','pen','pencil','Cricket ball','Fan','Chair']
random.shuffle(box)
l=input("WoW !!!! Congratulations @!!@ you got a lottery Enter which index item u want(0 to 6) >>>")
print "\nIn this lottery you got a",box[l],"\n We will sent this item to your home plz fill the below form \n"
print"\t\t*****************************\n\t\t* The lottery box items are *\n\t\t*****************************\t\t\n--------------------------------------------------------------------------\n",box,"\t\t\n--------------------------------------------------------------------------\n"
print"\t\t\t\t//**Lottery form**//"
name=raw_input("Enter your name here(What u gave first) >>>\n--------------\n")
while(n!=name):
name=raw_input("Please enter What u gave first) >>>\n--------------\n")
print("--------------")
p_n=input("Enter your phone number here >>>\n--------------\n")
print("--------------")
address=raw_input("Enter your address here in this form (vill,m.d,dist) >>>\n--------------\n")
print("--------------")
print"Thanq,",name," we will sent the","'",box[l],"'", "to your address\n"
pb=input("Please pay the bill......! here :")
if (pb==(s+b)):
print ("Thanq ....!")
elif(pb>s+b):
rb=pb-(s+b)
print "You will get ",rb," rupees "
gift()
else:
print "Total bill for your eating is ",s,"\n"
def gift():
if s>=150:
box=['A.C','P.C','T.V','Refrigerator','Dining table']
random.shuffle(box)
l=input("WoW !!!! Congratulations @!!@ you got a lottery Enter which index item u want(0 to 4)")
print "\nIn this lottery you got a",box[l],"\n We will sent this item to your home plz fill the below form \n"
print"\t\t*****************************\n\t\t* The lottery box items are *\n\t\t*****************************\t\t\n--------------------------------------------------------------------------\n",box,"\t\t\n--------------------------------------------------------------------------\n"
print"\t\t\t\t//**Lottery form**//"
name=raw_input("Enter your name here(What u gave first) >>>\n--------------\n")
while(n!=name):
name=raw_input("Please enter What u gave first) >>>\n--------------\n")
print("--------------")
p_n=input("Enter your phone number here >>>\n--------------\n")
print("--------------")
address=raw_input("Enter your address here in this form (vill,m.d,dist) >>>\n--------------\n")
print("--------------")
print"\nThanq,",name," we will sent the","'",box[l],"'", "to your address\n"
elif s>=100:
box=['Cricket bat','Volley ball','video game','5-books','Bag','Radio']
random.shuffle(box)
l=input("WoW !!!! Congratulations @!!@ you got a lottery Enter which index item u want(0 to 5) >>>")
print "\nIn this lottery you got a",box[l],"\nWe will sent this item to your home plz fill the below form \n"
print"\t\t*****************************\n\t\t* The lottery box items are *\n\t\t*****************************\t\t\n--------------------------------------------------------------------------\n",box,"\t\t\n--------------------------------------------------------------------------\n"
print"\t\t\t\t//**Lottery form**//"
name=raw_input("Enter your name here(What u gave first) >>>\n--------------\n")
while(n!=name):
name=raw_input("Please enter What u gave first) >>>\n--------------\n")
print("--------------")
p_n=input("Enter your phone number here >>>\n--------------\n")
print("--------------")
address=raw_input("Enter your address here in this form (vill,m.d,dist) >>>\n--------------\n")
print("--------------")
print"\nThanq,",name," we will sent the","'",box[l],"'", "to your address\n"
elif s>=50:
box=['watch','camera','pen','pencil','Cricket ball','Fan','Chair']
random.shuffle(box)
l=input("WoW !!!! Congratulations @!!@ you got a lottery Enter which index item u want(0 to 6) >>>")
print "\nIn this lottery you got a",box[l],"\n We will sent this item to your home plz fill the below form \n"
print"\t\t*****************************\n\t\t* The lottery box items are *\n\t\t*****************************\t\t\n--------------------------------------------------------------------------\n",box,"\t\t\n--------------------------------------------------------------------------\n"
print"\t\t\t\t//**Lottery form**//"
name=raw_input("Enter your name here(What u gave first) >>>\n--------------\n")
while(n!=name):
name=raw_input("Please enter What u gave first) >>>\n--------------\n")
print("--------------")
p_n=input("Enter your phone number here >>>\n--------------\n")
print("--------------")
address=raw_input("Enter your address here in this form (vill,m.d,dist) >>>\n--------------\n")
print("--------------")
print"\nThanq,",name," we will sent the","'",box[l],"'", "to your address\n"
pb=input("Please pay the bill......! here :")
if (pb==s):
print ("Thanq ....!")
elif(pb>s):
rb=pb-s
print "You will get ",rb," rupees "
gift()
hotel()
com=raw_input("If u want to write a comment on my program just press 1 :")
if com=='1':
class MyDialog:
def __init__(self, parent):
top = self.top = Toplevel(parent)
Label(top, text="Write your comment here").pack()
self.e = Entry(top)
self.e.pack(padx=5)
b = Button(top, text="OK", command=self.ok)
b.pack(pady=5)
def ok(self):
print "\n\tThankq..... for your comment"
cr=open("Comment.txt","a")
print "\n"
cr.write(self.e.get())
cr.close()
print "\nClose the side empty window\n"
self.top.destroy()
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
re=input("R u want to run this program again press any key expect 0(don't use characters):")
if (re==0):
print "\t\t\tThankq..........."
break
What are the translator used of python programming languange?
interactive interpreter more like a "shell" (if you're
a unix person).
How to use python programming to make graphing xy charts?
try using this code:
import pygame
def main():
(tab)screen = pygame.display.set_mode((750,750))
(tab)pygame.display.set_caption("graph")
(tab)screen.fill((255,255,255))
(tab)pygame.draw.line(screen, (0, 0, 0), (375, 0), (375, 750))
(tab)pygame.draw.line(screen, (0, 0, 0), (0, 375), (750, 375))
(tab)pygame.display.flip()
(tab)while True:
(tab)(tab)x = raw_input("x: ")
(tab)(tab)if x 'q':
(tab)(tab)(tab)pygame.quit()
(tab)(tab)(tab)break
(tab)(tab)print ''
(tab)(tab)screen.fill((255,255,255))
(tab)(tab)pygame.draw.line(screen, (0, 0, 0), (375, 0), (375, 750))
(tab)(tab)pygame.draw.line(screen, (0, 0, 0), (0, 375), (750, 375))
(tab)(tab)try:
(tab)(tab)(tab)pygame.draw.circle(screen, (0, 0, 255), (int(x) + 375, -1 * int(y) + 375), 3 )
(tab)(tab)except:
(tab)(tab)(tab)print "graph error, please enter valid x,y coordinates"
(tab)(tab)pygame.display.flip()
main()
pygame.quit()
this code makes a simple grapher.unfortunitly when I typed this answer, the tabs don't show up so I had to do this instead. any time it says "(tab)" just insert a tab there instead.