sandhyanv9/python-java-codegen-dataset
04
1{"instruction":"Write a complete Python program to print Hello World.","response":"def main():\n print('Hello World')\n\nif __name__ == '__main__':\n main()"}2{"instruction":"Write a complete Python program to add two numbers entered by the user.","response":"def main():\n a = float(input('Enter first number: '))\n b = float(input('Enter second number: '))\n print('Sum =', a + b)\n\nif __name__ == '__main__':\n main()"}3{"instruction":"Write a complete Python program to check whether a number is prime.","response":"def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return True\n\n\ndef main():\n n = int(input('Enter a number: '))\n if is_prime(n):\n print(f'{n} is prime')\n else:\n print(f'{n} is not prime')\n\nif __name__ == '__main__':\n main()"}4{"instruction":"Write a complete Python program to find the factorial of a number.","response":"def factorial(n):\n result = 1\n for i in range(2, n + 1):\n result *= i\n return result\n\n\ndef main():\n n = int(input('Enter a number: '))\n print('Factorial =', factorial(n))\n\nif __name__ == '__main__':\n main()"}5{"instruction":"Write a complete Python program to reverse a string entered by the user.","response":"def main():\n text = input('Enter a string: ')\n print(text[::-1])\n\nif __name__ == '__main__':\n main()"}6{"instruction":"Write a complete Python program to count vowels in a string.","response":"def count_vowels(text):\n vowels = 'aeiouAEIOU'\n return sum(1 for ch in text if ch in vowels)\n\n\ndef main():\n text = input('Enter a string: ')\n print('Vowel count =', count_vowels(text))\n\nif __name__ == '__main__':\n main()"}7{"instruction":"Write a complete Python program to remove duplicates from a list.","response":"def main():\n numbers = [1, 2, 2, 3, 4, 4, 5, 1]\n unique_numbers = list(dict.fromkeys(numbers))\n print('Original list:', numbers)\n print('Without duplicates:', unique_numbers)\n\nif __name__ == '__main__':\n main()"}8{"instruction":"Write a complete Python program to sort a list of numbers in ascending order.","response":"def main():\n numbers = [5, 2, 9, 1, 7, 3]\n numbers.sort()\n print('Sorted list:', numbers)\n\nif __name__ == '__main__':\n main()"}9{"instruction":"Write a complete Python program to check whether a string is a palindrome.","response":"def is_palindrome(text):\n cleaned = ''.join(ch.lower() for ch in text if ch.isalnum())\n return cleaned == cleaned[::-1]\n\n\ndef main():\n text = input('Enter a string: ')\n if is_palindrome(text):\n print('Palindrome')\n else:\n print('Not a palindrome')\n\nif __name__ == '__main__':\n main()"}10{"instruction":"Write a complete Python program to generate the first 10 Fibonacci numbers.","response":"def fibonacci(n):\n sequence = [0, 1]\n while len(sequence) < n:\n sequence.append(sequence[-1] + sequence[-2])\n return sequence[:n]\n\n\ndef main():\n print(fibonacci(10))\n\nif __name__ == '__main__':\n main()"}11{"instruction":"Write a complete Python program to read a text file and count the number of words.","response":"def main():\n file_path = 'sample.txt'\n try:\n with open(file_path, 'r', encoding='utf-8') as file:\n content = file.read()\n words = content.split()\n print('Word count =', len(words))\n except FileNotFoundError:\n print(f'File not found: {file_path}')\n\nif __name__ == '__main__':\n main()"}12{"instruction":"Write a complete Python program to create a dictionary from two lists and print it.","response":"def main():\n keys = ['name', 'age', 'city']\n values = ['Alice', 25, 'Bangalore']\n result = dict(zip(keys, values))\n print(result)\n\nif __name__ == '__main__':\n main()"}13{"instruction":"Write a complete Python program to convert Celsius to Fahrenheit.","response":"def celsius_to_fahrenheit(c):\n return (c * 9 / 5) + 32\n\n\ndef main():\n c = float(input('Enter temperature in Celsius: '))\n print('Fahrenheit =', celsius_to_fahrenheit(c))\n\nif __name__ == '__main__':\n main()"}