{"id":15797386,"url":"https://github.com/devqueue/cs-practical-repo","last_synced_at":"2025-03-31T19:43:59.144Z","repository":{"id":126913593,"uuid":"355925546","full_name":"devqueue/CS-practical-repo","owner":"devqueue","description":null,"archived":false,"fork":false,"pushed_at":"2021-04-12T04:58:54.000Z","size":1602,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-12T00:30:47.861Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devqueue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-08T13:49:03.000Z","updated_at":"2021-04-12T04:58:56.000Z","dependencies_parsed_at":"2023-06-18T21:32:20.638Z","dependency_job_id":null,"html_url":"https://github.com/devqueue/CS-practical-repo","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"c3605c0b44af0e1a31b2c604616d00c457bffccd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devqueue%2FCS-practical-repo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devqueue%2FCS-practical-repo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devqueue%2FCS-practical-repo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devqueue%2FCS-practical-repo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devqueue","download_url":"https://codeload.github.com/devqueue/CS-practical-repo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246531985,"owners_count":20792735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-05T00:07:38.652Z","updated_at":"2025-03-31T19:43:59.120Z","avatar_url":"https://github.com/devqueue.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CS-practical-repo\n\nAuthor: Hazique sayyed\n\n\u003ch1 align=\"center\"\u003ePYTHON\u003c/h1\u003e\n\n### Program 1\n##### Aim: To write a simple calculator to find sum, diference, product and division \n#### Source code: \n``` python\ndef add(x, y):\n    return x + y\n\ndef subtract(x, y):\n    return x - y\n\ndef multiply(x, y):\n    return x * y\n\ndef divide(x, y):\n    return x / y\n\nprint(\"Select operation.\")\nprint(\"1.Add\")\nprint(\"2.Subtract\")\nprint(\"3.Multiply\")\nprint(\"4.Divide\")\n\nwhile True:\n    choice = input(\"Enter choice(1/2/3/4): \")\n    if choice in ('1', '2', '3', '4'):\n        num1 = float(input(\"Enter first number: \"))\n        num2 = float(input(\"Enter second number: \"))\n\n        if choice == '1':\n            print(num1, \"+\", num2, \"=\", add(num1, num2))\n\n        elif choice == '2':\n            print(num1, \"-\", num2, \"=\", subtract(num1, num2))\n\n        elif choice == '3':\n            print(num1, \"*\", num2, \"=\", multiply(num1, num2))\n\n        elif choice == '4':\n            print(num1, \"/\", num2, \"=\", divide(num1, num2))\n        break\n    else:\n        print(\"Invalid Input\")\n```\n#### Output: \n\n![](media/program1_out.png)\n\n\n\n---\n### Program 2\n#### AIM: To Write a Python program to read a text file and remove all the lines that contains the character ‘a’ in the file and write it in another file\n#### Source code:\n```python\noldfile = open('content.txt')\nlines = oldfile.readlines()\nnewopen = open('newfile.txt', 'w')\n#print(lines)\n\nfor line in lines:\n    if 'a' in line:\n        #print(line)\n        newopen.write(line)\n        \nnewopen.close()\noldfile.close()\nprint(\"Contents copied over to newfile.txt\")\n```\n#### Output: \n\n\n![](media/program4_out.png)\n\n---\n\n### Program 3\n#### AIM: To write a Python program to read a text file line by line and display each word seperated by a #.\n#### Source code:\n```python\nwith open('story.txt', 'r') as f:\n    for line in f:\n        for word in line.split():\n            print(word, end=\"#\")\n    print('\\n')\n```\n\n#### Output: \n\n![](media/program5_out.png)\n\n\n---\n### Program 4\n#### AIM: To Write a Python program to read a text file line by line and display the number of vowels/ consonants / upper case letters and lower case characters.\n#### Source code:\n```python\nvowels = ['a','e','i','o','u']\nvowels_count = 0\nconsonat_count = 0\nupper_count = 0\nlower_count = 0\n\n\nfile = open('story.txt', 'r')\ndata = file.read()\nprint(data)\nfor ch in data:\n    if str.isupper(ch):\n        upper_count += 1\n    elif str.islower(ch):\n        lower_count += 1\n    ch2 = str.lower(ch)\n    if ch2 in vowels:\n        vowels_count+=1\n    elif ch2 not in vowels:\n        consonat_count+=1\n\nprint(f\"No. of vowels are {vowels_count}\")\nprint(f\"No. of constants are {consonat_count}\")\nprint(f\"No. of upper case are {upper_count}\")\nprint(f\"No. of lower case are {lower_count}\")\nfile.close()\n```\n\n#### Output: \n\n![](media/program6_out.png)\n\n\n---\n### Program 5\n#### AIM: To Write a Python program to create a binary file with roll number , name and marks. Input a roll number and update the marks.\n#### Source code:\n```python\nimport pickle\nimport pprint as pp\nimport sys\n\ndef Display(data):\n    data = {}\n    file = open(\"Student.pickle\", 'rb')\n    try:\n        while True:\n            Student = pickle.load(file)\n            pp.pprint(Student)\n    except EOFError:\n        file.close()\n\ndef Search(data):\n    data = {}\n    file = open(\"Student.pickle\", 'rb+')\n    reader = int(input(\"Enter the Roll No. to search: \"))\n    found = False\n    try:\n        while True:\n            data = pickle.load(file)\n            if data[\"Roll\"] == reader:\n                print(\"Record Found\")\n                print(data)\n                found = True\n                break\n    except EOFError:\n        if found == False:\n            print(\"Record not found \\n \\n\")\n        file.close()\n\ndef write_in_file(data):\n    data = {}\n    studs = int(input(\"Enter no. of students: \"))\n    file = open(\"Student.pickle\", \"rb+\")\n    for i in range(1,studs+1):\n        data[\"Roll\"] = int(input(\"Enter the Roll NO: \"))\n        data[\"Name\"] = input(\"Enter a name: \")\n        data[\"Marks\"] = float(input(\"Enter the marks: \"))\n        pickle.dump(data, file)\n        print(f\"{i} Record(s) Entered Sucessfully\")\n        data={}\n        \n    file.close()\n\ndef Update_marks(data):\n    data = {}\n    found = False\n    reader = int(input(\"Enter the Roll No. to update: \"))\n    file = open(\"Student.pickle\", 'rb+')\n\n    try:\n        while True:\n            pos = file.tell()\n            data = pickle.load(file)\n            if data[\"Roll\"] == reader:\n                print(\"Record Found\")\n                print(data)\n                data[\"Marks\"] = float(input(\"Enter the marks: \"))\n                file.seek(pos)\n                found = True\n                pickle.dump(data, file)\n                break\n    except EOFError:\n        if found == False:\n            print(\"Record not found \\n \\n\")\n        else:\n            print(\"Marks updated Sucessfully\")\n        file.close()\n\n    \nSdata = {}\n\n#main program\nwhile True:\n    print(\"Menu \\n 1-Write in a file \\n 2-display \\n 3-Search \\n 4-Update Marks \\n 5-exit\")\n    ch = int(input(\"Enter a Choice: \"))\n    if ch == 1:\n        write_in_file(Sdata)\n    if ch == 2:\n        Display(Sdata)\n    if ch == 3:\n        Search(Sdata)\n    if ch == 4:\n        Update_marks(Sdata)\n    if ch == 5:\n        sys.exit()\n\n```\n\n#### Output: \n\n\n![](media/program8_out.png)\n\n\n---\n### Program 6\n#### AIM: To write a Python program to read a text file ( story.txt) line by line and print it.\n#### Source code:\n``` python\nstory = \"story.txt\"\nwith open(story, \"r\") as f:\n    lines = f.readlines()\n    for line in lines:\n        print(line)\n```\n\n#### Output: \n\n\n![](media/program3_out.png)\n\n---\n### Connectivity:\n#### AIM: To execute an sql query using python\n#### Source code:\n```python\nimport mysql.connector as sqltor\nconnection = sqltor.connect(host=\"localhost\",user=\"root\",password=\"****!\",database='sales')\ncursor = connection.cursor()\ncursor.execute('Select * from orders where salesman_id=5001')\ndata = cursor.fetchall()\nprint (data)\ncursor.close()\nconnection.close()\n```\n\n#### Output: \n\n![](media/program19.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevqueue%2Fcs-practical-repo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevqueue%2Fcs-practical-repo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevqueue%2Fcs-practical-repo/lists"}