sc
1. 3,4,5,6A represent it in array
code:-
array = [3, 4, 5, "6A"]
for element in array:
print(element)
2. show * in array
code:-
#include <stdio.h>
int main() {
int array[] = { 1, 2, 3, 42};
printf("%d\n", array[0]);
printf("%d\n", array[1]);
printf("%d\n", array[2]);
printf("%c\n", array[3]);
return 0;
}
3. Calculate the no. of numerical digits in a string.
code:-
string = "Madhav 9034, I have 34 Rubbe4."
count = 0
for char in string:
if char.isdigit():
count = count + 1
print("Number of numerical digits:", count)
or
def count_digits(input_string):
count = sum(1 for char in input_string if char.isdigit())
return count
if __name__ == "__main__":
user_input = input("Enter a string: ")
digit_count = count_digits(user_input)
print(f"The number of numerical digits in the string is: {digit_count}")
4. Make a neuron which takes data as an input and check with a speific array of data on behalf of that give the output
code:-
def neuron(input_data):
predefined_data = [10, 20, 30, 40, 50]
if input_data in predefined_data:
return "Match found!"
else:
return "No match found"
input_data = 20
output = neuron(input_data)
print("Output:", output)
5. Write a program to move a number at an empty slot in an array {2,4,3,{},7}
code:-
array = [2, 4, 3, '{}', 7]
number_to_move = 5
array[array.index('{}')] = number_to_move
print("Updated array:", array)
6. Write a program to move a number at an empty slot in an array
code:-
array = [2, 4, 3, None, 7]
number_to_move = 5
array[array.index(None)] = number_to_move
print("Updated array:", array)
7. Write a program to implement sigmoid function
code:-
import math
def sigmoid(x):
return 1 / (1 + math.exp(-x))
x = 0.5
result = sigmoid(x)
print("Sigmoid result:", result)
8. ambiguious calculator
code :-
def ambiguous_calculator(expression):
try:
result = eval(expression)
return result
except Exception as e:
return "Invalid expression or ambiguity detected."
input_expression = input("Enter a mathematical expression: ")
output = ambiguous_calculator(input_expression)
print("Result:", output)
9. simple calculator
code:-
def calculator():
num1 = float(input("Enter first number: "))
operator = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if operator == "+":
return num1 + num2
elif operator == "-":
return num1 - num2
elif operator == "*":
return num1 * num2
elif operator == "/":
return num1 / num2
else:
return "Invalid operator"
result = calculator()
print("Result:", result)
Comments
Post a Comment