+ 1

Balconies

2 Tests Passe But 3 Left

28th Jul 2023, 7:56 AM
Aakash Gupta
Aakash Gupta - avatar
17 Respostas
+ 1
a = str(input()) #Ginormous for loop average user a_dim1 = "" a_dim2 = "" a_count = 0 for i in a: if i == ",": a_count += 1 a_dim1 = a[0:a_count-1] a_dim2 = a[a_count:] else: a_count += 1 a_area = float(a_dim1) * float(a_dim2) #Simple string func enjoyer b = str(input()) r = b.index(",") b_dim1 = b[:r] b_dim2 = b[r+1:] b_area = float(b_dim1) * float(b_dim2) #Area comparison w = a_area > b_area #Correct output based on comparison result if w: print("Apartment A") else: print("Apartment B")
29th Jul 2023, 4:41 PM
Pavlov K.
Pavlov K. - avatar
+ 5
Task description said only greather and your above mentioned code some others.
28th Jul 2023, 8:24 AM
JaScript
JaScript - avatar
+ 5
The problem is in receiving of input. The input are two strings and each of it has two numbers separated by comma. This must be implemented.
28th Jul 2023, 9:01 AM
JaScript
JaScript - avatar
+ 4
For learning is better to try yourself. You can write an attempt in SL Playground and test it. Here a hint: 1. Receive two strings, 2. Divide each string into two, one from before comma and the second from after the comma character. 3. Convert each to a number 4. And then you can use for the rest of your code above mentioned functions and if else statement. For more help please link your attempt from SL Playground with a concrete question.
28th Jul 2023, 10:20 AM
JaScript
JaScript - avatar
+ 4
Aakash Gupta , the input is still an issue. this is what the task description says: Sample Input '5,5' '2,10' to see what the input looks like, include an output of your variables (a, b, c, d) for temporary debugging.
28th Jul 2023, 5:44 PM
Lothar
Lothar - avatar
+ 2
Aakash Gupta there are two fundamental issues that are preventing the code from passing the tests. 1. Handling input 2. Calling the functions The scanf input format specifier string is often tricky to get right. Notice the example input has separating commas. If you insert the two commas in the scanf specifier string at just the right places, then scanf will read the integer values correctly and skip past the commas. The two area functions do the same calculation. Why not just define one function and call it for both calculations, say area(int length, int width)? Before the if statement, the code calls the area functions but does not use or store their results. You may as well delete those two lines. The if statement compares the addresses of the area functions. It does not call the functions and compare their return values. Make it call the functions there. If you fix the scanf format specifier and the if conditional so that it calls the functions, then the program should pass.
28th Jul 2023, 6:41 PM
Brian
Brian - avatar
0
#include <stdio.h> int areaA(int a, int b){ return a*b; } int areaB(int c, int d){ return c*d; } int main(){ int a,b,c,d; scanf("%d%d%d%d", &a , &b, &c, &d); areaA(a,b); areaB(c,d); if(areaA>=areaB){ printf("Apartment A"); } else{ printf("Apartment B"); } return 0; }
28th Jul 2023, 7:56 AM
Aakash Gupta
Aakash Gupta - avatar
0
Nothing Happens... still 2 passes
28th Jul 2023, 8:28 AM
Aakash Gupta
Aakash Gupta - avatar
0
Can you show me how can i implement?
28th Jul 2023, 9:08 AM
Aakash Gupta
Aakash Gupta - avatar
0
Aakash Gupta is that you are trying to solve python code? I can help you out in this.
29th Jul 2023, 12:36 PM
ā€Ž ąŗø
0
Hi! IDK if ur goal is solve it with Python or not, but checked ur account and saw that u do python as well In my code i used 2 different approaches to define the 1st element of input and 2nd (did that to familiarise myself with the material that i just learned) I'm a complete beginner so my code most likely isn't the best option but it passes the test. Basically what my code do is converting input into a string and defines first part of the input and second based on it position relatively the "," symbol (left part and right) Hope you'll find some insights in my code. Here it is: a = str(input()) #Ginormous for loop average user a_dim1 = "" a_dim2 = "" a_count = 0 for i in a: if i == ",": a_count += 1 a_dim1 = a[0:a_count-1] a_dim2 = a[a_count:] else: a_count += 1 a_area = float(a_dim1) * float(a_dim2) #Simple string func enjoyer b = str(input()) r = b.index(",") b_dim1 = b[:r] b_dim2 = b[r+1:] b_area = float(b_dim1) * float(b_dim2) #Area comparison w = a_area > b_area #Correct output based o
29th Jul 2023, 4:27 PM
Pavlov K.
Pavlov K. - avatar
0
#Correct output based on comparison result if w: print("Apartment A") else: print("Apartment B")
29th Jul 2023, 4:29 PM
Pavlov K.
Pavlov K. - avatar
0
Sorry Pavlov but it got error in its first linešŸ„². You can try this code on Balconies challenge in Code Coach section
29th Jul 2023, 4:35 PM
Aakash Gupta
Aakash Gupta - avatar
0
I will paste it as a separate message, and don't forget switch your language in the code coach to Python I copied it straight from my code section on this task and also checked it to be shure that it works
29th Jul 2023, 4:41 PM
Pavlov K.
Pavlov K. - avatar
0
Thank You Sir.. Actually It was my indentation mistake on previous one
29th Jul 2023, 4:45 PM
Aakash Gupta
Aakash Gupta - avatar
0
U're welcome ! This is my firs time answering to someone, got some shivers thank u ;D Started learning 5 days ago Good luck on ur programming journey :)
29th Jul 2023, 4:58 PM
Pavlov K.
Pavlov K. - avatar
0
Thank You Pavlov and You Too Good Luck
30th Jul 2023, 4:45 AM
Aakash Gupta
Aakash Gupta - avatar