+ 1
41.2 Practice Help - From Feet to inches
Problem: You need to make a function that converts a foot value to inches. 1 foot has 12 inches. Define a convert() function, that takes the foot value as argument and outputs the inches value. —————— Lost here again as it doesn’t explain well how to set and use the convert variable in the lesson. Code: feet = int(input()) def convert(feet) print(feet/12) print(feet) Thanks!
12 odpowiedzi
+ 10
feet = int(input())
def convert(ft):
inches = ft * 12
print(inches)
convert(feet)
+ 2
Your convert function should multiply the number of feet passed to it by 12 and output that value.
Remove the print(feet) and replace it with a call to the convert function passing the feet variable to it.
+ 2
Zach Z
When you call the convert() function you pass the value of the variable feet to the function. That value is held in the local function variable ft. The function definition is the part that starts with def and includes all the indented body. A function call is when you want to invoke that method by using its name followed by any required or optional arguments within parentheses.
convert(feet) # function call
You can call a function as many times as needed throughout your program.
+ 2
THIS IS CORRECT,GUYS
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);
}
}
+ 1
feet = int(input())
def convert(feet, inches):
print (feet * inches)
convert(feet, 12)
this is the best, try it. it is working perfect
0
ChaoticDawg little more guidance please. Still lost. Call to convert function?
0
Thanks ChaoticDawg !!
Curious, how does it know ft and feet are the same? I understand ft is short for feet but wouldnt that need to be stated for the code to understand? Thanks!
0
def convert(feet):
print(feet*12)
feet = int(input())
convert(feet)
0
foot = int(input())
def convert():
print(foot*12)
convert()
0
feet = int(input())
def convert(feet):
print(feet*12)
convert(feet)
0
feet = int(input())
def convert(a):
print(12 * a)
convert(feet)
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);
}
}