text
stringlengths
2
1.05k
def add_numbers(n1, n2): result = n1 + n2 print(result) add_numbers(2, 5)
#include <stdio.h> void findSquare(int* number) { int square = *number * *number; *number = square; } int main() { int number = 21; findSquare(&number); printf("Square is %d", number); return 0; }
#include <stdio.h> int main() { int age; printf("Enter your age: "); scanf("%d", &age); if (age >= 18) { printf("You are eligible to vote"); } return 0; }
#include <stdio.h> int main() { int age; printf("Enter your age: "); scanf("%d", &age); if (age >= 18) { printf("You are eligible to vote"); } if (age < 18) { printf("Sorry, you are not eligible to vote"); } return 0; }
try: numerator = int(input("Enter numerator: ")) denominator = int(input("Enter denominator: ")) result = numerator/denominator print(result) except ZeroDivisionError: print("Denominator cannot be 0. Try again.") print("Program ends")
import os print(os.listdir()) os.remove("<filename>") print(os.listdir())
def divide(a, b): return a/b
#include <stdio.h> int main() { int age = 25; printf("C Programming"); return 0; }
languages = ["Python", "Java", "Swift", "C", "C++"]
#include <stdio.h> int main() { int age; printf("Enter input value: "); scanf("%d", &age); printf("Age = %d", age); return 0; }
languages = ["Python", "JavaScript", "C++", "Kotlin"] languages1 = languages.copy() print(languages1)
#include <stdio.h> #include <stdbool.h> int main() { bool value = (9 < 9); printf("%d ", value); return 0; }
#include <stdio.h> #include <string.h> int main() { char food1[20]; char food2[20]; printf("Enter the first food: "); fgets(food1, sizeof(food1), stdin); printf("Enter the second food: "); fgets(food2, sizeof(food2), stdin); if (strlen(food1) > strlen(food2)) { printf("Longest Food Name: ...
result = list(range(1, 11, 3)) print(result)
#include <stdio.h> int main() { double a = 5.67; int b = 9; int result = a + b; printf("%d", result); return 0; }
score = 105 if score > 100 or score < 0: print("Score is invalid.") elif score >= 50: print("You have passed your exam.") print("Congratulations!") else: print("Sorry, you have failed your exam.")
#include <stdio.h> int main() { int age[5]; printf("Enter 5 input values: "); scanf("%d", &age[0]); scanf("%d", &age[1]); scanf("%d", &age[2]); scanf("%d", &age[3]); scanf("%d", &age[4]); printf("%d ", age[0]); printf("%d ", age[1]); printf("%d ", age[2]); printf("%d ", age[3]); printf("%d ...
switch(variable/expression) { case value1: // body of case 1 break; case value2: // body of case 2 break; case valueN: // body of case N break; default: // body of default }
13
with open('python.txt', 'w') as f: f.write("Python is awesome\n") f.write("I love Python")
import os current_dir = os.getcwd() print(current_dir)
numbers_list = [1, 2] print(dir(numbers_list))
languages = ["English", "French", "German"] for language in languages: print(language)
import os # rename directory or file os.rename('<old_name>', '<new_name>')
#include <stdio.h> int main() { int age = -4; if (age > 120) { printf("Invalid Age"); } else if (age < 0) { printf("Invalid age"); } else if (age >= 18) { printf("You are eligible to vote"); } else { printf("Sorry, you are not eligible to vote"); } return 0; }
#include <stdio.h> int main() { double a = 5.67; int b = 9; double result = a + b; printf("%lf", result); return 0; }
message = "How you doing?" def greet(): message = "How are you?" print("Message inside function:", message) greet() print("Message outside function:", message)
from game.characters.boss import get_boss_info get_boss_info()
person1 = {"name": "Linus", "age": 21} print(person1.get("hobbies", ["dancing", "fishing"]))
person1 = {"name": "Linus", "age": 21} print(person1["hobbies"])
class Student: pass student1 = Student() student2 = Student()
import os current_dir = os.getcwd() print(current_dir) os.chdir("<new location>") with open("test.txt", "w") as f: f.write("This is a test file.")
#include <stdio.h> int main() { int arr[2][3] = { {1, 3, 5}, {2, 4, 6} }; printf("%d\n", arr[0][0]); printf("%d", arr[1][2]); return 0; }
#include <stdio.h> int main() { int age = 25; printf("%d", age); return 0; }
count = 0 while count < 5: print("I am inside a Loop.") print("Looping is interesting.") count = count + 1
animals = {"dog", "cat", "tiger", "elephant", "dog"} animals.add("monkey") print(animals)
# change value of a variable city = "Kathmandu" print(city) city = "New York" print(city)
#include <stdio.h> int main() { int age = 10; printf("Age = %d", number); return 0; }
def add_numbers(n1, n2): result = n1 + n2 print("The sum is", result) add_numbers(5.4, 6.7)
# Print the type of input. number = input("Enter a number: ") print(type(number))
#include <stdio.h> int main() { FILE* fptr; fptr = fopen("test.txt", "r"); if (fptr != NULL) { printf("File Open Successful"); } else { printf("File Open Unsuccessful"); } return 0; }
31
# a list of integers numbers = [1, 5, 6, -4] print(len(numbers)) # empty list list1 = [] print(len(list1))
# assign one variable to another city = "Kathmandu" destination_city = "New York" city = destination_city print(city)
class Complex: def __init__(self, real, imag): self.real = real self.imag = imag def add(self, number): real = self.real + number.real imag = self.imag + number.imag result = Complex(real, imag) return result n1 = Complex(5, 6) n2 = Complex(-4, 2) result...
#include <stdio.h> int main() { int age = 25; printf("%p", &age); int* ptr = &age; printf("\n%p", ptr); return 0; }
with open('python.txt', 'r') as f: lines = f.readlines() print(lines)
def print_msg(message): greeting = "Hello" def printer(): print(greeting, message) printer() print_msg("Python is awesome")
animals = {"tiger", "cat", "elephant", "dog"} animals.discard("ferret") print(animals)
#include <stdio.h> int main() { int age = 130; if (age > 120) { printf("Invalid Age"); } else if (age < 0) { printf("Invalid age"); } else if (age >= 18) { printf("You are eligible to vote"); } else { printf("Sorry, you are not eligible to vote"); } return 0; }
#include <stdio.h> int main() { int number; printf("Enter a number between 1 to 7: "); scanf("%d", &number); switch(number) { case 1: printf("Sunday "); case 2: printf("Monday "); case 3: printf("Tuesday "); case 4: printf("Wednesday "); case 5: printf("T...
def greet(name, message): print("Hello", name) print(message) greet("Jack", "What's going on?") greet(message = "Howdy?", name = "Jill")
1
#include <stdio.h> int main() { int number; printf("Enter the number: "); scanf("%d", &number); int count = 1; while (count <= 10) { int product = number * count; printf(" %d * %d = %d \n", number, count, product); count = count + 1; } return 0; }
class Triangle: def __init__(self, a, b, c): # write code here pass # write code here t1 = Triangle(3, 4, 5) # write code here
0
int test(double num1, int num2) { ... }
#include <stdio.h> int main() { while (1 < 5) { printf("while loop in C \n"); } return 0; }
1
#include <stdio.h> int main() { double x = 12.00; double result = x / 8.00; printf("%.2lf", result); return 0; }
# print(1) # print(2) # print(3)
for item in range(1, 6): if item == 3: break print(item) print("The end")
class Polygon: def __init__(self, sides): self.sides = sides def display_info(self): print("A polygon is a two dimensional shape with straight lines") def get_perimeter(self): perimeter = sum(self.sides) return perimeter class Triangle(Polygon): def display_info(self)...
do { // body of loop } while(condition);
#include <stdio.h> void addNumbers(int number1, int number2) { int sum = number1 + number2; printf("Sum of %d and %d is %d", number1, number2, sum); } int main() { addNumbers(8, 9); return 0; }
test_condition ? expression1 : expression2;
import datetime as dt current_time = dt.datetime.now() next_new_year = dt.datetime(2022, 1, 1) time_remaining = next_new_year - current_time print(time_remaining) print(type(time_remaining))
import datetime as dt time1 = dt.time(10, 47, 20, 234566) print(time1) print("Hour:", time1.hour) print("Minute:", time1.minute) print("Second:", time1.second) print("Microsecond:", time1.microsecond)
animals = {"dog", "tiger", "elephant"} wild_animals = ["tiger", "leopard", "elephant"] animals.update(wild_animals, {"dolphin"}) print(animals)
from game.characters import player player.get_player_info()
def add_numbers(n1, n2): result = n1 + n2 add_numbers(2, 5) print(result)
import calculator result1 = calculator.add(2, 3) print(result1) result2 = calculator.subtract(6, 3) print(result2) result3 = calculator.multiply(10, 3) print(result3) result4 = calculator.divide(6, 3) print(result4)
#include <stdio.h> void greet() { printf("Good Morning\n"); } int main() { greet(); greet(); greet(); return 0; }
person1 = {"name": "Linus", "age": 21} print(person1["name"]) print(person1["age"])
class Animal: def eat(): print("I can eat") class Dog(Animal): def bark(self): print("I can bark") dog1 = Dog() dog1.bark() dog1.eat()
result1 = True result2 = False print(result1) # True print(result2) # False
#include <stdio.h> int main() { while(1) { int number; printf("\nEnter any number: "); scanf("%d", &number); if (number < 0 && number % 2 != 0) { printf("%d", number); } e...
0
#include <stdio.h> int main() { int a = 5; float a = 9.3; printf("%d", a); }
result = range(1, 11) print(result)
name = input("Enter name: ") # age = int(input("Enter age: ")) print(name) # print(age)
class Triangle: def __init__(self, a, b, c): self.a = a self.b = b self.c = c def get_perimeter(self): perimeter = self.a + self.b + self.c return perimeter t1 = Triangle(3, 4, 5) perimeter = t1.get_perimeter() print("The perimeter of the t1 triangle is", perim...
text = "Python" new_text = text * 3 print(new_text)
text = "I like Python 3" result = text.replace("Python 3", "Java") print(result)
&& Logical AND || Logical OR ! Logical Not
#include <stdio.h> int main() { int age; double height; printf("Enter the age: "); scanf("%d", &age); printf("Enter the height: "); scanf("%lf", &height); printf("Age = %d", age); printf("\nHeight = %.1lf", height); return 0; }
def greet(name): print("Hello", name) print("How do you do?") greet("Jack")
#include <stdio.h> int main() { int number; printf("Enter a number between 1 to 7: "); scanf("%d", &number); switch(number) { case 1: printf("Sunday"); break; case 2: printf("Monday"); break; case 3: printf("Tuesday"); break; case 4: printf("Wednes...
int arr[1][4] = { {3, 6, 9, 12}, {2, 4, 6, 8} };
def generate_fibonacci(): n1 = 0 yield n1 n2 = 1 yield n2 while True: n1, n2 = n2, n1 + n2 yield n2 seq = generate_fibonacci() print(next(seq)) print(next(seq)) print(next(seq)) print(next(seq)) print(next(seq))
number1 = 5 print(id(number1)) number2 = number1 print(id(number2))
text = "I like Python 3" result = text.lower() print(result)
#include <stdio.h> int main() { int age; double number; printf("int size = %zu", sizeof (age)); printf("\ndouble size = %zu", sizeof(number)); return 0; }
def printer(): print("Hello, World!") def display_info(func): def inner(): print("Executing",func.__name__,"function") func() print("Finished execution") return inner
def inc(x): return x + 1 def operate(func, x): result = func(x) return result print(operate(inc, 3))
text = "He said, "What's there?"" print(text)
# Python sequences text = "Python" languages = ['English', 'French', 'German']
for (int i = 1; i < 5; i++) {...}
#include <stdio.h> int main() { int age[5]; printf("Enter 5 input values: "); for (int i = 0; i < 5; ++i) { scanf("%d", &age[i]); } for (int i = 0; i < 5; ++i) { printf("%d ", age[i]); } return 0; }
number = int(input("Enter an integer: ")) for count in range(1, 11): product = number * count print(number, "*", count, "=", product)