Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import pymysql
  2. import sys
  3. from readTask import tampil
  4.  
  5. connection = pymysql.connect(
  6.     host='localhost',
  7.     user='root',
  8.     password='',
  9.     db='buku',
  10. )
  11.  
  12. def jualbuku():
  13.     tampil()
  14.     beli = input('pilih judul buku : ')
  15.     jml_buku = int(input('masukan jumlah buku : '))
  16.     try:
  17.         with connection.cursor() as cursor:
  18.             sql2 = "SELECT `title`, `harga` FROM buku"
  19.             try:
  20.                 cursor.execute(sql2)
  21.                 jdl = cursor.fetchone()[0]
  22.                 hrg = int(cursor.fetchone()[1])
  23.                 if beli == jdl:
  24.                     total = jml_buku * hrg
  25.                     print('jumlah bayar buku ',total)
  26.             except pymysql.Error as e:
  27.                 print("Oops! Something wrong", e)
  28.         connection.commit()
  29.     finally:
  30.         connection.close()
  31.  
  32. if __name__=='__main__':
  33.     jualbuku()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement