Programda şarkı eklemek için 2 .komutu seçiyorum. Lakin verileri girmeme izin vermeden atlıyor ve ekteki hatayı alıyorum. Veri tipini int yaptım float yaptım aynı şekilde. Veritabanı içerisinden değiştirdim. Ama hiçbir şekilde sonuç alamadım. Problem nedir? Cevap için şimdiden teşekkürler.
Python:
import sqlite3
import time
class music():
def __init__(self,name,artist,album,company,duration):
self.name=name
self.artist=artist
self.album=album
self.company=company
self.duration=duration
def __str__(self):
return "Name of the song: {}\n" \
"Name of the artist: {}\n" \
"Name of the album: {}\n" \
"Name of the company: {}\n" \
"Duration of the song: {}\n"\
.format(self.name, self.artist, self.album, self.company, self.duration )
class library():
def __init__(self):
self.create_connection=sqlite3.connect("music.db")
self.cursor=self.create_connection.cursor()
query="Create Table If not Exists music(Name TEXT, Artist TEXT, Album TEXT, Company TEXT, Duration INT)"
self.cursor.execute(query)
self.create_connection.commit()
def disconnect(self):
self.create_connection.close()
def show_information(self):
query="Select*From music"
self.cursor.execute(query)
songs=self.cursor.fetchall()
if (len(songs)==0):
print("There are no songs in your song playlist")
else:
for i in songs:
song=music(i[0],i[1],i[2],i[3],i[4])
print(song)
def add_song(self,name):
query="Insert Into music Values(?,?,?,?,?)"
self.cursor.execute(query,(name.name,name.artist,name.album,name.company,name.duration))
self.create_connection.commit()
def del_song(self,name):
query="Delete From music where Name=?"
self.cursor.execute(query,(name,))
self.create_connection()
def search_song(self,name):
query="Select*From music where Name=?"
self.cursor.execute(query,(name,))
song=self.cursor.fetchall()
if (len(song)==0):
print("The song you were looking for could not be found.")
else:
song=music(song[0][0], song[0][1], song[0][2], song[0][3], song[0][4])
print(song)
def calculate_duration(self):
query="Select*From music"
self.cursor.execute(query)
list=self.cursor.fetchall()
duration=0
for i in list:
duration=duration+float(i[4])
print("The total duration of the songs in the track list is: {}", duration)
library=library()
print("""
-----------------------
Library Sqlite3
-----------------------
1- Songs in playlist
2- Add song
3- Delete song
4- Calculate the duration of songs
q- Exit
-----------------------
""")
while True:
process=input("Enter the operation you want to perform:")
if (process=="q"):
print("The program is being terminated...")
library.disconnect()
break
elif (process == "1"):
library.show_information()
elif (process == "2"):
name=print("Enter the name of the song you want to add:")
artist = print("Enter the artist of the song you want to add:")
album = print("Enter the album name of the song you want to add:")
company = print("Enter the company name of the song you want to add:")
duration = float(print("Enter the duration of the song you want to add:"))
new_song=music(name,artist,album,company,duration)
print("The song is being added to the library...")
time.sleep(1)
library.add_song(new_song)
print("The song has been added to the library.")
elif (process == "3"):
name=print("Enter the name of the song you want to delete:")
answer=input("Are you sure: (Y/N)")
if (answer == "Y"):
print("The song is being terminated from the library...")
time.sleep(1)
library.del_song(name)
print("The song has been deleted to the library.")
elif (process == "4"):
library.calculate_duration()
else:
print("Invalid operation!")
Dosya Ekleri
Son düzenleyen: Moderatör: