Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7036419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:25:18+00:00 2026-05-28T01:25:18+00:00

I am new at python. Here is my wiered python code Which works fine

  • 0

I am new at python. Here is my wiered python code Which works fine for all inputs except

when c=0 and r!=0 .

I have number of test case(tc) , r and c as inputs which give required output depending condition.

Question—For input r=4 & c=0 ,Output Should be 2,but output is coming 1 . I am geting wrong answer for every r!=0 & c=0.

Code:

tc=int(input())
while tc:
     r,c=raw_input().split()
     if int(r)%2==0 and r!=2 and r!=0 and c!=0:
        r=int(r)/2
     elif r!=2 and r!=0 and c!=0:
        r=int(r)/2+1
     elif r==0 or r ==2:
        r=1
     if r!=0:
        if int(c)!=0:
           print(int(r)*int(c))
        else :
           if int(r)%2==0 :
              print(int(r)/2)
            else:
               r=int(r)/2+1
               print(r) 
     else :
        print(c);
     tc=tc-1

sample input and output

4         //tc
10 10     //r=10 c= 10
50        //fine
3 3       //r=3 c=3
6         //fine
4 0        //r=4 c=0
1         //Should be 2 accoring to code
5 0      //r=5 c=0
2       //Output should be 3 accoring to the code
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:25:19+00:00Added an answer on May 28, 2026 at 1:25 am

    You have solved the mystery yourself (kind of):

    if int(r)%2==0 and r!=2 and r!=0 and c!=0:
    

    r is a string. So r will always be !=2 because "2" != 2 is always true. Same goes for all the other comparisons.

    I’m guessing you first got a TypeError with if r%2==0, so you changed that bit of the program (also in all the other places where you’re actually doing calculations with the values) but neglected to apply this insight to the other parts of the program.

    So first convert all your inputs to ints, then start applying your program logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new at Python. Here is my code which scans number of test
I'm new to python, and have a list of longs which I want to
I'm new to Python. Here I've written a Python program which retrieves values from
I am new to Python. Here's what I am trying to do: Slice a
I am new to Python, and I'm working on writing some database code using
I am really new to Python and I have been looking for an example
Today I have come across a surprising definition of a metaclass in Python here
New to python and django .i want to understand the code of django-registration module
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
Disclaimer: I am new to python and django but have Drupal programming experience. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.