如何正确使用小于和大于签名的Python

时间:2017-02-05 10:21:14

标签: python

所以我的脚本中有以下功能:

def age():
    global age
    age = raw_input("Age: ")

    if age == 14:
        sleep(1)
        print ("LOL, same")

    elif age < 18:
        sleep(1)
        print ("This test is made for contestants older than ten")
        introduction()  

    elif age > 18:
        sleep(1)
        print ("Geez grandpa, you sure are old")

当我运行它时,它会像我这样注册我输入的每个年龄18:

  

你能告诉我你的年龄吗?

     

年龄:4

     

Geez爷爷,你确定已经老了

为什么会这样做?

2 个答案:

答案 0 :(得分:3)

func addPinOnMap(_ address: String) { var hotelClass = PFObject(className: HOTEL_CLASS_NAME) hotelClass = hotelArray[0] if mapView.annotations.count != 0 { annotation = mapView.annotations[0] mapView.removeAnnotation(annotation) } // Make a search on the Map localSearchRequest = MKLocalSearchRequest() localSearchRequest.naturalLanguageQuery = address localSearch = MKLocalSearch(request: localSearchRequest) localSearch.start { (localSearchResponse, error) -> Void in // Add PointAnnonation text and a Pin to the Map self.pointAnnotation = MKPointAnnotation() self.pointAnnotation.title = "\(hotelClass[HOTEL_NAME]!)" self.pointAnnotation.coordinate = CLLocationCoordinate2D( latitude: localSearchResponse!.boundingRegion.center.latitude, longitude:localSearchResponse!.boundingRegion.center.longitude) self.pinView = MKPinAnnotationView(annotation: self.pointAnnotation, reuseIdentifier: nil) self.mapView.centerCoordinate = self.pointAnnotation.coordinate self.mapView.addAnnotation(self.pinView.annotation!) // Zoom the Map to the location self.region = MKCoordinateRegionMakeWithDistance(self.pointAnnotation.coordinate, 1000, 1000); self.mapView.setRegion(self.region, animated: true) self.mapView.regionThatFits(self.region) self.mapView.reloadInputViews() } } 将用户输入作为字符串类型返回时,您应该将其转换为int。

改变这个:

raw_input

要:

age = raw_input("Age: ")

答案 1 :(得分:0)

您的raw_input被视为字符串

function format(n) {
  var _n = n;
  // count the position of the first decimal
  var count = 0;
  do {
    n = n * 10;
    count++;
  } while(n < 1);
  return _n.toFixed(count + 2);
}


var num = 0.000000022732;

console.log(format(num));

因此,如果要将其与数字进行比较,则需要将其转换为整数值。

age = raw_input("Age: ")