import turtle as t
playerAscore=0
playerBscore=0
window=t.Screen()
window.title("Pong Game")
window.bgcolor("green")
window.setup(width=800,height=600)
window.tracer(0)
#creating left paddle
leftpaddle=t.Turtle()
leftpaddle.speed(0)
leftpaddle.shape("square")
leftpaddle.color("white")
leftpaddle.shapesize(stretch_wid=5,stretch_len=1)
leftpaddle.penup()
leftpaddle.goto(-350,0)
#creating right paddle
rightpaddle=t.Turtle()
rightpaddle.speed(0)
rightpaddle.shape("square")
rightpaddle.color("white")
rightpaddle.shapesize(stretch_wid=5,stretch_len=1)
rightpaddle.penup()
rightpaddle.goto(350,0)
#creating ball
ball=t.Turtle()
ball.speed(0)
ball.shape("circle")
ball.color("red")
ball.penup()
ball.goto(5,5)
ballxdirection=0.2
ballydirection=0.2
#creating pen for scorecard update
pen=t.Turtle()
pen.speed(0)
pen.color("red")
pen.penup()
pen.hideturtle()
pen.goto(0,260)
pen.write("score",align="center",font=('Arial',24,'normal'))
#moving the leftpaddle
def leftpaddleup():
y=leftpaddle.ycor()
y=y+90
leftpaddle.sety(y)
def leftpaddledown():
y=leftpaddle.ycor()
y=y-90
leftpaddle.sety(y)
#moving the right paddle
def rightpaddleup():
y=rightpaddle.ycor()
y=y+90
rightpaddle.sety(y)
def rightpaddledown():
y=rightpaddle.ycor()
y=y-90
rightpaddle.sety(y)
#Assign keys to play
window.listen()
window.onkeypress(leftpaddleup,'w')
window.onkeypress(leftpaddledown,'s')
window.onkeypress(rightpaddleup,'Up')
window.onkeypress(rightpaddledown,'Down')
while True:
window.update()
#moving the ball
ball.setx(ball.xcor()+ballxdirection)
ball.sety(ball.ycor()+ballydirection)
#settingup border
if ball.ycor()>290:
ball.sety(290)
ballydirection=ballydirection*-1
if ball.ycor()<-290:
ball.sety(-290)
ballydirection=ballydirection*-1
if ball.xcor()>390:
ball.goto(0,0)
ballxdirection=ballxdirection
playerAscore=playerAscore+1
pen.clear()
pen.write("player A:{} player B:{}".format(playerAscore,playerBscore),align='center',font=('Arial',24,'normal'))
if(ball.xcor())<-390:
ball.goto(0,0)
ballxdirection=ballxdirection*-1
playerBscore=playerBscore+1
pen.clear()
pen.write("player A:{} player B:{}".format(playerAscore,playerBscore),align='center',font=('Arial',24,'normal'))
#Handling the Collisions
if (ball.xcor()>340)and(ball.xcor()<350)and(
ball.ycor()<rightpaddle.ycor()+40 and ball.ycor()>rightpaddle.ycor()-40):
ball.setx(340)
ballxdirection=ballxdirection*-1
if (ball.xcor()<-340)and(ball.xcor()>-350)and(
ball.ycor()<leftpaddle.ycor()+40 and ball.ycor()>leftpaddle.ycor()-40):
ball.setx(-340)
ballxdirection=ballxdirection*-1
playerAscore=0
playerBscore=0
window=t.Screen()
window.title("Pong Game")
window.bgcolor("green")
window.setup(width=800,height=600)
window.tracer(0)
#creating left paddle
leftpaddle=t.Turtle()
leftpaddle.speed(0)
leftpaddle.shape("square")
leftpaddle.color("white")
leftpaddle.shapesize(stretch_wid=5,stretch_len=1)
leftpaddle.penup()
leftpaddle.goto(-350,0)
#creating right paddle
rightpaddle=t.Turtle()
rightpaddle.speed(0)
rightpaddle.shape("square")
rightpaddle.color("white")
rightpaddle.shapesize(stretch_wid=5,stretch_len=1)
rightpaddle.penup()
rightpaddle.goto(350,0)
#creating ball
ball=t.Turtle()
ball.speed(0)
ball.shape("circle")
ball.color("red")
ball.penup()
ball.goto(5,5)
ballxdirection=0.2
ballydirection=0.2
#creating pen for scorecard update
pen=t.Turtle()
pen.speed(0)
pen.color("red")
pen.penup()
pen.hideturtle()
pen.goto(0,260)
pen.write("score",align="center",font=('Arial',24,'normal'))
#moving the leftpaddle
def leftpaddleup():
y=leftpaddle.ycor()
y=y+90
leftpaddle.sety(y)
def leftpaddledown():
y=leftpaddle.ycor()
y=y-90
leftpaddle.sety(y)
#moving the right paddle
def rightpaddleup():
y=rightpaddle.ycor()
y=y+90
rightpaddle.sety(y)
def rightpaddledown():
y=rightpaddle.ycor()
y=y-90
rightpaddle.sety(y)
#Assign keys to play
window.listen()
window.onkeypress(leftpaddleup,'w')
window.onkeypress(leftpaddledown,'s')
window.onkeypress(rightpaddleup,'Up')
window.onkeypress(rightpaddledown,'Down')
while True:
window.update()
#moving the ball
ball.setx(ball.xcor()+ballxdirection)
ball.sety(ball.ycor()+ballydirection)
#settingup border
if ball.ycor()>290:
ball.sety(290)
ballydirection=ballydirection*-1
if ball.ycor()<-290:
ball.sety(-290)
ballydirection=ballydirection*-1
if ball.xcor()>390:
ball.goto(0,0)
ballxdirection=ballxdirection
playerAscore=playerAscore+1
pen.clear()
pen.write("player A:{} player B:{}".format(playerAscore,playerBscore),align='center',font=('Arial',24,'normal'))
if(ball.xcor())<-390:
ball.goto(0,0)
ballxdirection=ballxdirection*-1
playerBscore=playerBscore+1
pen.clear()
pen.write("player A:{} player B:{}".format(playerAscore,playerBscore),align='center',font=('Arial',24,'normal'))
#Handling the Collisions
if (ball.xcor()>340)and(ball.xcor()<350)and(
ball.ycor()<rightpaddle.ycor()+40 and ball.ycor()>rightpaddle.ycor()-40):
ball.setx(340)
ballxdirection=ballxdirection*-1
if (ball.xcor()<-340)and(ball.xcor()>-350)and(
ball.ycor()<leftpaddle.ycor()+40 and ball.ycor()>leftpaddle.ycor()-40):
ball.setx(-340)
ballxdirection=ballxdirection*-1
👍2❤1
class Human:
def init(self,name,height,weight):
self.name=name
self.height=height
self.weight=weight
def eating(self,food):
return("{} is eating {}".format(self.name,food))
#creating objects
ram=Human("Ram",6,60)
praveen=Human("Praveen",5.9,56)
arun=Human("Arun",6.0,50)
#Retreiving the object information
print("Height of {} is {}".format(ram.name,ram.height))
print("weight of {} is {}".format(ram.name,ram.weight))
print(ram.eating("Pizza"))
print("Height of {} is {}".format(praveen.name,praveen.height))
print("weight of {} is {}".format(praveen.name,praveen.weight))
print(praveen.eating("banana"))
print("Height of {} is {}".format(arun.name,arun.height))
print("weight of {} is {}".format(arun.name,arun.weight))
print(arun.eating("Rice"))
def init(self,name,height,weight):
self.name=name
self.height=height
self.weight=weight
def eating(self,food):
return("{} is eating {}".format(self.name,food))
#creating objects
ram=Human("Ram",6,60)
praveen=Human("Praveen",5.9,56)
arun=Human("Arun",6.0,50)
#Retreiving the object information
print("Height of {} is {}".format(ram.name,ram.height))
print("weight of {} is {}".format(ram.name,ram.weight))
print(ram.eating("Pizza"))
print("Height of {} is {}".format(praveen.name,praveen.height))
print("weight of {} is {}".format(praveen.name,praveen.weight))
print(praveen.eating("banana"))
print("Height of {} is {}".format(arun.name,arun.height))
print("weight of {} is {}".format(arun.name,arun.weight))
print(arun.eating("Rice"))
#creating chatbot
from chatterbot import ChatBot
chatbot=ChatBot(
'Akpython',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapter=[
'chatterbot.logic.MathematicalEvaluation',
'chatterbot.logic.TimeLogicAdapter',
'chatterbot.logic.BestMatch',
{
'import_path':'chatterbot.logic.BestMatch',
'default_response':'I am sorry,I do not understand',
'maximum_similarity_threshold':0.90
}
],
database_uri='sqlite:///database.sqlite3'
)
#Training
from chatterbot.trainers import ListTrainer
trainer=ListTrainer(chatbot)
trainingdata=open('/home/arun/Documents/Trainingdata').read().splitlines()
#Training the corpus
from chatterbot.trainers import ChatterBotCorpusTrainer
trainercorpus=ChatterBotCorpusTrainer(chatbot)
trainercorpus.train(
'chatterbot.corpus.english'
)
#BetterBot
name=input("Enter your name:")
print('Welcome to our Hotel',name,'Let me know how can I help you?')
while True:
request=input(name+':')
if request=='Bye'or request=='bye':
print("Bot:Bye")
break
else:
response=chatbot.get_response(request)
print('Bot:',response)
from chatterbot import ChatBot
chatbot=ChatBot(
'Akpython',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapter=[
'chatterbot.logic.MathematicalEvaluation',
'chatterbot.logic.TimeLogicAdapter',
'chatterbot.logic.BestMatch',
{
'import_path':'chatterbot.logic.BestMatch',
'default_response':'I am sorry,I do not understand',
'maximum_similarity_threshold':0.90
}
],
database_uri='sqlite:///database.sqlite3'
)
#Training
from chatterbot.trainers import ListTrainer
trainer=ListTrainer(chatbot)
trainingdata=open('/home/arun/Documents/Trainingdata').read().splitlines()
#Training the corpus
from chatterbot.trainers import ChatterBotCorpusTrainer
trainercorpus=ChatterBotCorpusTrainer(chatbot)
trainercorpus.train(
'chatterbot.corpus.english'
)
#BetterBot
name=input("Enter your name:")
print('Welcome to our Hotel',name,'Let me know how can I help you?')
while True:
request=input(name+':')
if request=='Bye'or request=='bye':
print("Bot:Bye")
break
else:
response=chatbot.get_response(request)
print('Bot:',response)