0
I want to convert feet into inches using function
i created this code but ut is'nt working def function(foot=int(input())): inches = 12 * foot print(inches) function(foot)
5 Respostas
+ 1
Although I'm sure that this code was made not knowing what you were doing (so go study now)
To make it work the last line should be:
function()
Without any indentation
0
Hi Tarun!
That's not a proper way to declare an argument as input variable. You can declare it before the defining or calling the function.
And also, function should be called in a same vertical line to its defined function.
Here it is your corrected code.
foot = int(input())
def function(foot):
inches = 12 * foot
print(inches)
#foot can be declared here too
#foot = int(input())
function(foot)
0
Tarun The way in which you've constructed your code gives me a feeling that you don't practice much coding; so try to go through the basics one more time, and everything will be fine. Here is the correct code:
def to_inch(foot):
print(foot * 12)
to_inch(int(input()))
# Happy coding!
0
Here is correct code in JavaScript
let foot = parseInt(readLine(), 10);
/* Define the convert() function */
function convert (foot) {
console.log(foot * 12)
}
convert(foot);
0
In Java
import java.util.Scanner;
public class Main{
static void convert(double foot) {
double inch = foot * 12;
double num = inch;
System.out.println(num);
}
//your code goes here
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double num = sc.nextDouble();
convert(num);
}
}
It runs smoothly