import sys
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication, QStackedWidget, QWidget, QTableWidget
import pymysql
import ast
import mysql.connector as mc
from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QPrintPreviewDialog
from pymysql import connections
from PyQt5.QtGui import QTextCursor
from PyQt5 import QtWidgets, QtCore, QtPrintSupport, QtGui


class WelcomeScreen(QDialog):

    def __init__(self):
        super(WelcomeScreen, self).__init__()
        loadUi("welcomescreen.ui", self)
        self.pbLoginX.clicked.connect(self.gotologinX)
        self.pbCreateX.clicked.connect(self.gotocreateX)
        self.pbConnectX.clicked.connect(self.gotoconnectX)
        self.pbQuitX.clicked.connect(self.gotoQuitX)

             # setting image to the button
    #self.pushButton.setStyleSheet("background-image : url(sekolah1.png);")

    def gotologinX(self):
        login = LoginScreen()
        widget.addWidget(login)
        widget.setCurrentIndex(widget.currentIndex()+1)

    def gotocreateX(self):
        create = CreateAccScreen()
        widget.addWidget(create)
        widget.setCurrentIndex(widget.currentIndex()+1)

    def gotoconnectX (self):
        con = pymysql.connect(db='dbsisfo', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        if(cur):
            self.messagebox("Koneksi", "Koneksi Berhasil")
        else:
            self.messagebox("Koneksi", "Koneksi Gagal")

    def messagebox(self, title, message):
        mess = QtWidgets.QMessageBox()
        mess.setWindowTitle(title)
        mess.setText(message)
        mess.setStandardButtons(QtWidgets.QMessageBox.Ok)
        mess.exec_()

    def gotoQuitX (self):
        sys.exit()

class LoginScreen(QDialog):
    def __init__(self):
        super(LoginScreen, self).__init__()
        loadUi("loginscreen.ui", self)

        self.pbLoginX.clicked.connect(self.login)
        self.pbCancelX.clicked.connect(self.Hapus)
        self.bLogout.clicked.connect(self.logout)

    def login(self):
        try:
            username = self.username.text()
            password = self.password.text()
            mydb = pymysql.connect(
            host="localhost",
            user="root",
            password="",
            database="dbsisfouas"
            )
 
            mycursor = mydb.cursor()
            mycursor.execute("SELECT username, password from datauser where username like '"+ username + "'and password like '"+ password +"'")
            result = mycursor.fetchone()
 
            if result == None:
                self.labelResult.setText("Incorrect username & Password")
 
            else:
                self.labelResult.setText("You are logged in")    
                mydialog = MAIN_MENU()
                widget.addWidget(mydialog)
                widget.setCurrentIndex(widget.currentIndex()+1)

        except pymysql.Error as e:
            self.labelResult.setText("Error")
    
    def Hapus(self):
        username = self.username.setText(" ")
        password = self.password.setText(" ")

    def logout(self):
        mydialog = WelcomeScreen()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class CreateAccScreen(QDialog):
    def __init__(self):
        super(CreateAccScreen, self).__init__()
        loadUi("createacc.ui", self)

        self.bClear.clicked.connect(self.Hapus)
        self.bLogout.clicked.connect(self.logout)
        self.bSave.clicked.connect(self.save)
        self.bCheck.clicked.connect(self.Tampil)
        self.bUpdate.clicked.connect(self.update)  
        self.bDelete.clicked.connect(self.delete)                         

    def save(self):
        username = self.username.text()
        password = self.password.text()
        insert = (username, password)
        print(insert)
        con = pymysql.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        sql = "INSERT INTO datauser(username, password)" + \
                  "VALUES"+str(insert)
        datauser = cur.execute(sql)
        if(datauser):
            self.messagebox("SUKSES", "Data user Tersimpan")
        else:
             self.messagebox("GAGAL", "Data user Gagal Tersimpan")    

    def messagebox(self, title, message):
        mess = QtWidgets.QMessageBox()
        mess.setWindowTitle(title)
        mess.setText(message)
        mess.setStandardButtons(QtWidgets.QMessageBox.Ok)
        mess.exec_()


    def Tampil(self):
        username = self.username.text()
        db = pymysql.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM datauser WHERE username='"+str(username)+"'")

        datauser = cursor.fetchall()
        if (datauser):
           for tp in datauser:
                self.username.setText("" + tp[0])
                self.password.setText("" + tp[1])
                self.messagebox("INFO","Data Ada")
        else:
                self.messagebox("INFO", "Data belum ada")  


    def update(self):
        username = self.username.text()
        password = self.password.text()
        con = pymysql.connect(db='dbsisfo', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        sql = "UPDATE datauser SET password=%s, username=%s"
        datauser = cur.execute(sql, (password, username))
        if (datauser):
             self.messagebox("SUKSES", "Data Berhasil Di Update")
        else:
            self.messagebox("GAGAL", "Data Gagal Di Update")    

    def delete(self):
        username = self.username.text()
        con = pymysql.connect(db='dbsisfo', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        sql = "DELETE FROM datauser where username=%s"
        datauser= cur.execute(sql, (username))
        if (datauser):
            self.messagebox("SUKSES", "Data Berhasil Di HAPUS")
        else:
            self.messagebox("GAGAL", "Data GAGAL Di HAPUS")           
  
    def Hapus(self):
        self.username.setText(" ")
        self.password.setText(" ")

    def logout(self):
        mydialog = WelcomeScreen()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class MAIN_MENU (QDialog):
    def __init__(self):
        super(MAIN_MENU, self).__init__()
        loadUi("MainMenu.ui", self)

        self.pbProfil.clicked.connect(self.Profil)
        self.pbErapor.clicked.connect(self.Erapor)
        self.pbOrganisasi.clicked.connect(self.Organisasi)  
        self.pbLogout.clicked.connect(self.logout)  
        self.pbFasilitas.clicked.connect(self.Fasilitas)

    def Profil (self):
        mydialog = PROFIL()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

    def Erapor (self):
        mydialog = E_RAPOR()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

    def Organisasi (self):
        mydialog = ORGANISASI()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

    def Fasilitas (self):
        mydialog = FASILITAS ()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

    def logout (self):
        mydialog = WelcomeScreen ()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class PROFIL (QDialog):
    def __init__(self):
        super(PROFIL, self).__init__()
        loadUi("Profil.ui", self)

        self.pbBackX.clicked.connect(self.backX)  

    def backX(self):
        mydialog = MAIN_MENU()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class E_RAPOR (QDialog):
    def __init__(self):
        super(E_RAPOR, self).__init__()
        loadUi("DataSiswa.ui", self)

        self.bClear.clicked.connect(self.Hapus)
        self.bEdit.clicked.connect(self.Edit)
        self.bCheck.clicked.connect(self.Tampil)
        self.bUpdate.clicked.connect(self.update)  
        self.bDelete.clicked.connect(self.delete)  
        self.bBackX.clicked.connect(self.backX)  
        self.bSearch.clicked.connect(self.SearchData)
        self.bPrintFileX.clicked.connect(self.PrintFile)  
        self.bPrintPreviewX.clicked.connect(self.printPreviewDialog)  
        self.bLoadDataX.clicked.connect(self.LoadDataX)
        self.LoadDataX()

    def LoadDataX(self):
        db = mc.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)        
        mycursor = db.cursor()
        mycursor.execute("SELECT * FROM dataguru")
        result = mycursor.fetchall()
        self.tableWidget.setRowCount(0)

        for row_number, row_data in enumerate(result):
            self.tableWidget.insertRow(row_number)
            for column_number, data in enumerate(row_data):
                self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
        mycursor.close()

    def Edit(self, __init__):
        mydialog = DATA_GURU()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

    def messagebox(self, title, message):
        mess = QtWidgets.QMessageBox()
        mess.setWindowTitle(title)
        mess.setText(message)
        mess.setStandardButtons(QtWidgets.QMessageBox.Ok)
        mess.exec_()

    def Tampil(self):
        nama = self.nama.text()
        db = pymysql.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM dataguru WHERE nama='"+str(nama)+"'")
        dataguru = cursor.fetchall()
        if (dataguru):
            for tp in dataguru:
                self.nama.setText("" + tp[1])
                self.nis.setText("" + tp[2])
                self.kelas.setText("" + tp[3])
                self.messagebox("INFO","Data Ada")
        else:
                self.messagebox("INFO", "Data belum ada")  


    def update(self):
        nama = self.nama.text()
        nis = self.nis.text()
        kelas = self.kelas.text()
        birthday = self.birthday.text()
   
        con = pymysql.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        sql = "UPDATE dataguru SET nis=%s, kelas=%s, birthday=%s WHERE nama=%s"
        dataguru = cur.execute(sql, (nis, kelas, birthday, nama))
        if (dataguru):
             self.messagebox("SUKSES", "Data Berhasil Di Update")
        else:
            self.messagebox("GAGAL", "Data Gagal Di Update")    

    def delete(self):
        nama = self.nama.text()
        con = pymysql.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        sql = "DELETE FROM dataguru where Nama=%s"
        datasiswa = cur.execute(sql, (nama))
        if (dataguru):
            self.messagebox("SUKSES", "Data Berhasil Di HAPUS")
        else:
            self.messagebox("GAGAL", "Data GAGAL Di HAPUS")           
    
    def SearchData(self):

        nama = self.nama.text()
        db = mc.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cursor = db.cursor()

        cursor.execute("SELECT * FROM dataguru WHERE nama='"+str(nama)+"'")        

        dataguru = cursor.fetchall()

        if (dataguru):
            self.tableWidget.setRowCount(0)
            for row_number, row_data in enumerate(datasiswa):
                self.tableWidget.insertRow(row_number)
                for column_number, data in enumerate(row_data):
                    cell = QtWidgets.QTableWidgetItem(str(data))
                    self.tableWidget.setItem(row_number, column_number,cell)
        else:
                self.messagebox("INFO", "Data belum ada")  
  
    def Hapus(self):
        self.nama.setText(" ")
        self.nis.setText(" ")
        self.kelas.setText(" ")

    def backX(self):
        mydialog = MAIN_MENU()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    
    def PrintFile(self):
        printer = QPrinter(QPrinter.HighResolution)
        dialog = QPrintDialog(printer, self)
        if dialog.exec() == QPrintDialog.accepted:
            self.texEdit.print_(printer)


    def printPreviewDialog(self):
        printer = QPrinter(QPrinter.HighResolution)
        previewDialog = QPrintPreviewDialog(printer, self)
        previewDialog.paintRequested.connect(self.print_preview)
        previewDialog.exec_()

    def print_preview(self, printer):
            self.textEdit.print_(printer)

class ORGANISASI (QDialog):
    def __init__(self):
        super(ORGANISASI, self).__init__()
        loadUi("Organisasi.ui", self)
        self.pbBackX.clicked.connect(self.BackX) 
 
    def BackX(self):
        mydialog = MAIN_MENU()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class FASILITAS (QDialog):
    def __init__(self):
        super(FASILITAS, self).__init__()
        loadUi("Fasilitas.ui", self)
        self.pbBack.clicked.connect(self.BackX)  
        self.pbKelas.clicked.connect(self.Kelas)
        self.pbPerpus.clicked.connect(self.Perpus)
        self.pbWifi.clicked.connect(self.Wifi)
        self.pbLab.clicked.connect(self.Lab)
        self.pbLap.clicked.connect(self.Lapangan)
        self.pbKantin.clicked.connect(self.Kantin)
        self.pbIT.clicked.connect(self.IPTEK)
        self.pbMasjid.clicked.connect(self.Masjid)
 
    def BackX(self):
        mydialog = MAIN_MENU()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def Kelas (self):
        mydialog = RUANG_KELAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def Perpus (self):
        mydialog = PERPUSTAKAAN()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def Wifi (self):
        mydialog = WIFI()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def Lab (self):
        mydialog = LABORATORIUM()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def Lapangan (self):
        mydialog = LAPANGAN()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def Kantin (self):
        mydialog = KANTIN()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def IPTEK (self):
        mydialog = IT()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    def Masjid (self):
        mydialog = MASJID()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class RUANG_KELAS (QDialog):
    def __init__(self):
        super(RUANG_KELAS, self).__init__()
        loadUi("Kelas.ui", self)
        
        self.pbBack.clicked.connect(self.backX)  

    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class PERPUSTAKAAN (QDialog):
    def __init__(self):
        super(PERPUSTAKAAN, self).__init__()
        loadUi("Perpustakaan.ui", self)
        self.pbBack.clicked.connect(self.backX)
    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class WIFI (QDialog):
    def __init__(self):
        super(WIFI, self).__init__()
        loadUi("wifi.ui", self)
        self.pbBack.clicked.connect(self.backX)
    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class LABORATORIUM (QDialog):
    def __init__(self):
        super(LABORATORIUM, self).__init__()
        loadUi("Labsains.ui", self)
        self.pbBack.clicked.connect(self.backX)
    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class LAPANGAN (QDialog):
    def __init__(self):
        super(LAPANGAN, self).__init__()
        loadUi("Olahraga.ui", self)
        self.pbBack.clicked.connect(self.backX)
    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class KANTIN (QDialog):
    def __init__(self):
        super(KANTIN, self).__init__()
        loadUi("Kantin.ui", self)
        self.pbBack.clicked.connect(self.backX)
    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class MASJID (QDialog):
    def __init__(self):
        super(MASJID, self).__init__()
        loadUi("Masjid.ui", self)
        self.pbBack.clicked.connect(self.backX)
    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class IT (QDialog):
    def __init__(self):
        super(IT, self).__init__()
        loadUi("LabKom.ui", self)
        self.pbBack.clicked.connect(self.backX)
    def backX(self):
        mydialog = FASILITAS()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)

class DATA_GURU (QDialog):
    def __init__(self):
        super(DATA_GURU, self).__init__()
        loadUi("DataGuru.ui", self)

        self.pbSimpan.clicked.connect(self.SaveData)
        self.pbHitung.clicked.connect(self.Hitung)
        self.pbHapus.clicked.connect(self.ClearData)
        self.pbBackX.clicked.connect(self.BackX)  
        self.pbPrint.clicked.connect(self.PrintFile)
        self.pbUpdate.clicked.connect(self.update)
        self.pbLoadDataX.clicked.connect(self.LoadDataX)
        self.leNilaiRata.setDisabled(True)
        self.leNilaiSikap.setDisabled(True)
        self.leTotalNilai.setDisabled(True)

    def SaveData(self):
        nama = self.leNama.text()
        nis = self.leNIS.text()
        birthday = self.birthday.text()
        kelas = self.leKelas.text()
        Nilai_Rata_Rata = self.leNilaiRata.text()
        Total_Nilai = self.leTotalNilai.text()
        self[str(cmbNilaiSikap)].connect(self.change_text)
        Nilai_Sikap = self.leNilaiSikap.text()



        insert = (nama, nis, birthday, kelas, Nilai_Rata_Rata, Total_Nilai, Nilai_Sikap)
        print(insert)
        con = pymysql.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        sql = "INSERT INTO dataguru(nama, nis, birthday, kelas, Nilai_Rata_Rata, Total_Nilai, Nilai_Sikap)" + \
                  "VALUES"+str(insert)
        dataguru = cur.execute(sql)
        sql = sql.replace("'Null'", "Null")

    def Hitung (self):
        
        self.leNilaiRata.setDisabled(False)
        self.leNilaiSikap.setDisabled(False)
        self.leTotalNilai.setDisabled(False)
                
        if str(self.cmbSikap.currentText()) == "A":               
            leNilaiSikap = " A "
            self.cmbSikap.setText(" "+ str(leNilaiSikap))
        elif str(self.cmbSikap.currentText()) == "B":               
            leNilaiSikap = " B "
            self.cmbSikap.setText(" "+ str(leNilaiSikap))
        elif str(self.cmbSikap.currentText()) == "C":               
            leNilaiSikap = " C "
            self.cmbSikap.setText(" "+ str(leNilaiSikap))
        elif str(self.cmbSikap.currentText()) == "D":               
            leNilaiSikap = " D "
            self.cmbSikap.setText(" "+ str(leNilaiSikap))    
        else:
            leNilaiSikap = "tidak terdefinisi"
            self.cmbNilaiSikap.setText(" " + str(leNilaiSikap))

        IPA = int(self.sbIPA.text())
        IPS = int(self.sbIPS.text())
        Matematika = int(self.sbMM.text())
        total = ((IPA) + (IPS) + (Matematika)) 
        NilaiRataRata = ((IPA) + (IPS) + (Matematika)) / (3)
        self.leNilaiRata.setText(" " + str (NilaiRataRata))

        if self.rbDiskon10.isChecked():
            diskon=(10/100)* (total)
        elif self.rbDiskon20.isChecked():
            diskon=(20/100)* (total)
        elif self.rbDiskon30.isChecked():
            diskon=(30/100)* (total)
        else:
            diskon=0

        Nilaitotal = total - diskon

        self.leTotalNilai.setText(" " + str (Nilaitotal))

    def update(self):

        nama = self.leNama.text()
        nis = self.leNIS.text()
        birthday = self.birthday.text()
        kelas = self.leKelas.text()
        Persentase_Kehadiran = self.gbKehadiran.text()
        Nilai_Rata_Rata = self.leNilaiRata.text()
        Total_Nilai = self.leTotalNilai.text()
        Nilai_Sikap = self.leNilaiSikap.text()
        
        insert = (nama, nis, birthday, kelas, Nilai_Sikap, Nilai_Rata_Rata)
        print(insert)
        con = pymysql.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)
        cur = con.cursor()
        sql = "UPDATE dataguru SET nis=%s, kelas=%s, birthday=%s, Nilai_Sikap=%s, Persentase_Kehadiran=%s, Nilai_Rata_Rata=%s, Total_Nilai=%s, WHERE nama=%s"
        dataguru = cur.execute(sql, (nis, kelas, birthday, Jenis_Kelamin, Nilai_Sikap, Persentase_Kehadiran, Nilai_Rata_Rata, Total_Nilai, nama))

        if (dataguru):
             self.messagebox("SUKSES", "Data Berhasil Di Update")
        else:
            self.messagebox("GAGAL", "Data Gagal Di Update") 

    def ClearData (self):
        self.leNilaiRataRata.setText(" ")
        self.leNama.setText(" ")
        self.leNIS.setText(" ")
        self.leKelas.setText(" ")
        self.leTotalNilai.setText(" ")
        self.leNilaiSikap.setText (" ")
        
    def BackX (self):
        mydialog = MAIN_MENU()
        widget.addWidget(mydialog)
        widget.setCurrentIndex(widget.currentIndex()+1)
    
    def PrintFile(self):
        printer = QPrinter(QPrinter.HighResolution)
        dialog = QPrintDialog(printer, self)
        if dialog.exec() == QPrintDialog.accepted:
            self.texEdit.print_(printer)
        
    def LoadDataX(self):
        db = mc.connect(db='dbsisfouas', user='root', passwd='', host='localhost', port=3306, autocommit=True)        
        mycursor = db.cursor()
        mycursor.execute("SELECT * FROM dataguru")
        result = mycursor.fetchall()
        self.tableWidget.setRowCount(0)

        for row_number, row_data in enumerate(result):
            self.tableWidget.insertRow(row_number)
            for column_number, data in enumerate(row_data):
                self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
        mycursor.close()

#main
app = QApplication(sys.argv)
welcome=WelcomeScreen()
widget = QStackedWidget()
widget.addWidget(welcome)
widget.setFixedHeight(800)
widget.setFixedWidth(1200)
widget.show()
try:
   sys.exit(app.exec_())  
except:
    print("Exiting")       

Python Online Compiler

Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.

Taking inputs (stdin)

OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.

import sys
name = sys.stdin.readline()
print("Hello "+ name)

About Python

Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.

Tutorial & Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition IF-ELSE is used.

if conditional-expression
    #code
elif conditional-expression
    #code
else:
    #code

Note:

Indentation is very important in Python, make sure the indentation is followed correctly

2. For:

For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.

Example:

mylist=("Iphone","Pixel","Samsung")
for i in mylist:
    print(i)

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while condition  
    #code 

Collections

There are four types of collections in Python.

1. List:

List is a collection which is ordered and can be changed. Lists are specified in square brackets.

Example:

mylist=["iPhone","Pixel","Samsung"]
print(mylist)

2. Tuple:

Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.

Example:

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)

Below throws an error if you assign another value to tuple again.

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)

3. Set:

Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.

Example:

myset = {"iPhone","Pixel","Samsung"}
print(myset)

4. Dictionary:

Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.

Example:

mydict = {
    "brand" :"iPhone",
    "model": "iPhone 11"
}
print(mydict)

Supported Libraries

Following are the libraries supported by OneCompiler's Python compiler

NameDescription
NumPyNumPy python library helps users to work on arrays with ease
SciPySciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation
SKLearn/Scikit-learnScikit-learn or Scikit-learn is the most useful library for machine learning in Python
PandasPandas is the most efficient Python library for data manipulation and analysis
DOcplexDOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling