Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql
- import sys
- from readTask import tampil
- connection = pymysql.connect(
- host='localhost',
- user='root',
- password='',
- db='buku',
- )
- def jualbuku():
- tampil()
- beli = input('pilih judul buku : ')
- jml_buku = int(input('masukan jumlah buku : '))
- try:
- with connection.cursor() as cursor:
- sql2 = "SELECT `title`, `harga` FROM buku"
- try:
- cursor.execute(sql2)
- jdl = cursor.fetchone()[0]
- hrg = int(cursor.fetchone()[1])
- if beli == jdl:
- total = jml_buku * hrg
- print('jumlah bayar buku ',total)
- except pymysql.Error as e:
- print("Oops! Something wrong", e)
- connection.commit()
- finally:
- connection.close()
- if __name__=='__main__':
- jualbuku()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement