像這則例子,
var React = require('react');
var ReactDOM = require('react-dom');
var Child = require('./Child');
var Parent = React.createClass({
getInitialState: function () {
return { name: 'Frarthur' };
},
changeName: function (newName) {
this.setState({
name: newName
});
},
render: function () {
return (
<Child
name={this.state.name}
onChange={this.changeName} />
);
}
});
//因為需要定義作用中function,所以一定要記得加上this啊~~
ReactDOM.render(
<Parent />,
document.getElementById('app')
);
2017年2月12日 星期日
2017年2月8日 星期三
基本Python寫法:超市算術
#首先我們給個list
shopping_list = ["banana", "orange", "apple"]
#定義Dictionary
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
# 定義函數,裡面有個變數food,然後利用條件式,如果有庫存就加進總計,庫存減一
def compute_bill(food):
total= 0
for number in food:
if stock[number] > 0:
total += prices[number]
stock[number] -= 1
return total
shopping_list = ["banana", "orange", "apple"]
#定義Dictionary
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
# 定義函數,裡面有個變數food,然後利用條件式,如果有庫存就加進總計,庫存減一
def compute_bill(food):
total= 0
for number in food:
if stock[number] > 0:
total += prices[number]
stock[number] -= 1
return total
訂閱:
文章 (Atom)