Sadia is a good girl. She likes numbers but only even numbers. Today she wants to play a game with you. Sadia gives you two integer numbers. You will find an average of it. but here is a problem. Sadia don’t like the odd numbers, now you have to rescue yourself. You have to find the average for Sadia.
This program is very simple, the program should be able to read two numbers and print the even average of them.
Can you make happy with her?
test_cases = int(input("Number of test cases"))
for i in range(test_cases):
a = int(input("Give a number: "))
b = int(input("Give another number: "))
c = (a+b)/2
if c%2 == 0:
print("Sadia will be happy.")
else:
print("Oops!")
NoBody told you to print "Number of test cases" or "Give a number: " or "Give another number: "
Your output format should be in the way that is expected in the problem statement.
Just remove those strings from the input() function and your code should be accepted.
test_cases = int(input())
d = []
for i in range(test_cases):
a, b = map(int, input().split())
c = (a + b) / 2
if c % 2 == 0:
d.append(“Sadia will be happy.”)
else:
d.append(“Oops!”)
for i in d:
print(i)
@Abdullah_1234
at least try to implement what I told you before asking in the community.
I have tried submitting your code using // operator and it works.
You have no reason for getting Runtime Error
Why you use for loop here?
Solusion is :
num_1 = int(input(‘enter number 1’))
num_2 = int(input(‘enter number 2’))
if num_1 + num_2 % 2 == 0:
print('samia will be happy ')
else:
print(‘oops’)
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n, c = 0, d = 0, k = 0, avg;
System.out.print("Enter How many times you wanna Check(1 to 10) : ");
n = input.nextInt();
if (n >= 1 && n <= 10) {
int[][] num = new int[n][n];
//taking value
for (int i = 0; i < n; i++) {
System.out.println("Enter your 2 number for row " + (i + 1) + " : ");
c = 0;
k = 0;
for (int j = 0; j < 2; j++) {
num[i][j] = input.nextInt();
if (num[i][j] >= 1 && num[i][j] <= 100) {
k = k + num[i][j];
} else {
d++;
}
}
avg = k / 2;
if (avg % 2 == 0) {
c++;
}
if (d > 0) {
System.out.println("Print valid number");
break;
} else if (c == 1) {
System.out.println("Sadia Will be Happy");
} else {
System.out.println("Opps!");
}
}
} else {
System.out.println("Print valid number");
}
}
Just print the desired output. Nothing more or nothing less. Dont print anything unnecessary and you need to print a new line after each time you print anything. New solvers often get into this situation.