# What's wrong with this code?

Page 1 of 1

## 5 Replies - 744 Views - Last Post: 18 December 2014 - 02:59 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=360160&amp;s=59b070c73517709246b7c484e0d2f01b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 FlapperJacker

Reputation: 0
• Posts: 10
• Joined: 22-November 14

# What's wrong with this code?

Posted 18 December 2014 - 01:50 PM

When inputting equilateral triangle it works. While loop also works. I was able to get it working in c, but not python.

Python code:
```while True:
Side1 = input("Please enter side 1\n")
Side2 = input("Please enter side 2 \n")
Side3 = input("Please enter side 3 \n")
if Side1==Side2 and Side2==Side3:
print("The Triangle is Equilateral");
elif Side1*Side1+Side2*Side2==Side3*Side3 or Side3*Side3+Side2*Side2==Side1*Side1 or Side1*Side1+Side3*Side3==Side2*Side2:
print("It is a right triangle")
else:
printf("It is neither a right triangle or an equilateral triangle")
y = input("\nWould you like to try again? 1 for yes, 2 for no.\n")
if y==1:
break

```

c code:

```#include <stdio.h>

void inputFunction(float *, float *, float *);
void outputFunction(float, float, float);

int main()
{
float Side1,Side2,Side3;
int y=1;
while (y==1)
{
inputFunction(&Side1,&Side2,&Side3);
outputFunction(Side1,Side2,Side3);
printf("\nWould you like to try again? 1 for yes, 2 for no.\n");
scanf("%d", &y);

}
}
void inputFunction(float*Side1, float*Side2, float*Side3)
{
scanf("%f", Side1);
scanf("%f", Side2);
scanf("%f", Side3);
}

void outputFunction(float Side1, float Side2, float Side3)
{
if (Side1==Side2 && Side2==Side3)
{
printf("The Triangle is Equilateral");
}
else if ((Side1*Side1)+(Side2*Side2)==(Side3*Side3) || (Side3*Side3)+(Side2*Side2)==(Side1*Side1) || (Side1*Side1)+(Side3*Side3)==(Side2*Side2))
{
printf("It is a right triangle");
}
else
{
printf("It is neither a right triangle or an equilateral triangle");
}
}

```

Is This A Good Question/Topic? 0

## Replies To: What's wrong with this code?

### #2 andrewsw

• Unprocessable Entity

Reputation: 6594
• Posts: 26,833
• Joined: 12-December 12

## Re: What's wrong with this code?

Posted 18 December 2014 - 02:01 PM

If the C version works then why don't you use the same bracketing that you use in the C version in the Python version? I haven't inspected to see if it makes a difference, but it is what I would attempt first.

### #3 modi123_1

• Suitor #2

Reputation: 14352
• Posts: 57,556
• Joined: 12-June 08

## Re: What's wrong with this code?

Posted 18 December 2014 - 02:01 PM

Quote

What's wrong with this code?

I was able to get it working in c, but not python.

Please elaborate. What is not working? *HOW* is it not working? etc.

### #4 FlapperJacker

Reputation: 0
• Posts: 10
• Joined: 22-November 14

## Re: What's wrong with this code?

Posted 18 December 2014 - 02:14 PM

When I enter an equilateral triangle it works and when it asks if I want to try again it works. However when I enter a different type of triangle it doesn't work.
Traceback (most recent call last):
File "C:/Python34/hello world.py", line 7, in <module>
elif Side1*Side1+Side2*Side2==Side3*Side3 or Side3*Side3+Side2*Side2==Side1*Side1 or Side1*Side1+Side3*Side3==Side2*Side2:
TypeError: can't multiply sequence by non-int of type 'str'

This post has been edited by andrewsw: 18 December 2014 - 02:20 PM
Reason for edit:: Removed previous quote, just press REPLY

### #5 andrewsw

• Unprocessable Entity

Reputation: 6594
• Posts: 26,833
• Joined: 12-December 12

## Re: What's wrong with this code?

Posted 18 December 2014 - 02:19 PM

input() always returns a string, you need to use int() or float() to convert them to numbers (having checked that they are valid numbers of course).

It works for if Side1==Side2 and Side2==Side3 because you can compare strings, but you cannot multiply a string.

This post has been edited by andrewsw: 18 December 2014 - 02:20 PM

### #6 FlapperJacker

Reputation: 0
• Posts: 10
• Joined: 22-November 14

## Re: What's wrong with this code?

Posted 18 December 2014 - 02:59 PM

andrewsw, on 18 December 2014 - 01:19 PM, said:

input() always returns a string, you need to use int() or float() to convert them to numbers (having checked that they are valid numbers of course).

It works for if Side1==Side2 and Side2==Side3 because you can compare strings, but you cannot multiply a string.

Thanks it worked by changing them to floats