Team Ai
Datasetpublic

sandhyanv9/python-java-codegen-dataset

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes4downloads
valid.jsonl12 linesDownload Raw Back to root
1{"instruction":"Write a complete Python program to check whether a year is a leap year.","response":"def is_leap_year(year):\n    return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n\n\ndef main():\n    year = int(input('Enter a year: '))\n    if is_leap_year(year):\n        print(f'{year} is a leap year')\n    else:\n        print(f'{year} is not a leap year')\n\nif __name__ == '__main__':\n    main()"}2{"instruction":"Write a complete Python program to find the largest number in a list.","response":"def main():\n    numbers = [12, 45, 7, 89, 23]\n    print('Largest number:', max(numbers))\n\nif __name__ == '__main__':\n    main()"}3{"instruction":"Write a complete Python program to count the occurrences of each character in a string.","response":"from collections import Counter\n\n\ndef main():\n    text = input('Enter a string: ')\n    counts = Counter(text)\n    print(dict(counts))\n\nif __name__ == '__main__':\n    main()"}4{"instruction":"Write a complete Python program to merge two dictionaries.","response":"def main():\n    dict1 = {'a': 1, 'b': 2}\n    dict2 = {'c': 3, 'd': 4}\n    merged = {**dict1, **dict2}\n    print(merged)\n\nif __name__ == '__main__':\n    main()"}5{"instruction":"Write a complete Python program to find the sum of all even numbers from 1 to 100.","response":"def main():\n    total = sum(i for i in range(1, 101) if i % 2 == 0)\n    print('Sum of even numbers:', total)\n\nif __name__ == '__main__':\n    main()"}6{"instruction":"Write a complete Python program to convert a string to title case.","response":"def main():\n    text = input('Enter text: ')\n    print(text.title())\n\nif __name__ == '__main__':\n    main()"}7{"instruction":"Write a complete Python program to read a JSON file and print its contents.","response":"import json\n\n\ndef main():\n    file_path = 'sample.json'\n    try:\n        with open(file_path, 'r') as file:\n            data = json.load(file)\n        print(data)\n    except FileNotFoundError:\n        print('File not found')\n\nif __name__ == '__main__':\n    main()"}8{"instruction":"Write a complete Python program to find common elements between two lists.","response":"def main():\n    list1 = [1, 2, 3, 4, 5]\n    list2 = [4, 5, 6, 7, 8]\n    common = list(set(list1) & set(list2))\n    print(common)\n\nif __name__ == '__main__':\n    main()"}9{"instruction":"Write a complete Python program to sort a dictionary by its values.","response":"def main():\n    data = {'a': 3, 'b': 1, 'c': 2}\n    sorted_data = dict(sorted(data.items(), key=lambda item: item[1]))\n    print(sorted_data)\n\nif __name__ == '__main__':\n    main()"}10{"instruction":"Write a complete Python program to generate a random password of length 8.","response":"import random\nimport string\n\n\ndef main():\n    password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8))\n    print(password)\n\nif __name__ == '__main__':\n    main()"}11 12