Learn to Program(1)

本文介绍了编程的基础概念,包括数值运算、字符串操作、变量赋值等基本语法,并深入探讨了字符串方法、数学运算及随机数生成等内容。
Learn to Program(1)

0. Getting Started
1. Numbers
1.1 Introduction to puts
puts simply writes onto the screen whatever comes after it.

1.2 Integer and Float
numbers without decimal points are called integers, and nunbers with decimal points are usually called floating-point numbers(floats).

1.3 Simple Arithmetic
addition + subtraction - multiplication * division /

2. Letters
2.1 String Arithmetic
puts 'I like' + 'applie pic.' #add string

puts 'blink ' * 4 #multiply string
7*3 really just means 7 + 7 + 7, so 'blink ' * 3 just means 'blink ' + 'blink ' + 'blink '

2.2 12 vs '12'
12 is a number, '12' is a string of two digits.

2.3 Problems
puts '12' + 12
puts '2' * '5'

error message: : can't convert Fixnum into String (TypeError)

And 'pig' * 5 is ok, but 5 * 'pig' is silly.

puts 'You're well!' =====> puts 'You\'re well!'

3. Variables and Assignment
Using vairables
str = '...you can say hello...'
puts str
puts str

We can assign an object to a variable, we can reassgin a different object to that variable.
var = 'just go go go'
puts var
var = 5 * (1 + 2)
puts var

In fact, variables can point to just about anything... except other variables.
var1 = 8
var2 = var1
puts var1
puts var2

var1 = 'eight'
puts var1
puts var2

And the result is:
8 8 eight 8

4. Mixing It Up
4.1 Conversions
Using .to_s to get the string version of an object.
puts 2.to_s + '5'

Using to_i gieves the integer version of an object, to_f gives the float version.
puts 2 + '5'.to_i

puts 99.99.to_i
puts '5 is a number'.to_f
puts 'number 5 is here'.to_i

and the result is 99, 5, 0

4.2 Another Look at Puts
Before puts tries to write out an object, it uses to_s to get the string version of that object. In fact, the s in puts stands for string.

4.3 The Methods gets and chomp
gets just sits there, reading what you type until you press Enter.
puts gets

puts gets.chomp

chomp takes off any Enters hanging out at the end of your string.

5. More About Methods
Every verb needs a noun, so every method needs an object.

If I say puts ' something', what I am really saying is self.puts ' something'.

5.1 Fancy String Methods
string method reverse which gives a backwards version of a string.
var1 = 'stop'
var2 = 'love'

puts var1.reverse
puts var2.reverse

Its results are pots, evol, it is really stange to see the string reverse.

var = 'carl'
puts 'the length of string carl is ' + var.length.to_s

upcase changes every lowercase letter to uppercase.
downcase changes every uppercase letter to lowercase.
swapcase switches the case of every leter in the string
capitalize is just like downcase, except that it switches the first character to uppercase.

var = 'caRl'
puts var.upcase
puts var.downcase
puts var.swapcase
puts var.capitalize

center adds spaces to the beginning and end of the string to make it cenered.
lineWidth = 50
puts('carl is a good guy'.center(lineWidth))

ljust and rjust, which stand for left justify and right justify. They are similar to center.

5.2 Higher Math
% puts 7%3 shows 1

abs, it just takes the absolute value of the number.
puts((-3).abs)

5.3 Random Numbers
The method to get a randomly chosen number is rand.
puts rand
puts rand
puts rand(100)
puts rand(100)

Note that I used rand(101) to get back numbers from 0 to 100, and that rand(1) always gives back 0.
Not understanding the range of possible return values is the biggest mistake.

srand ---> seed and rand

5.4 The Math Object
puts(Math::PI)
puts(Math.sqrt(4))

results: 3.14...., 2.0

references:
http://pine.fm/LearnToProgram/?Chapter=00
多源数据接入 支持校园各业务系统数据接入:包括教务系统(学生成绩、课程信息)、学工系统(奖惩记录、资助信息)、后勤系统(宿舍分配、能耗数据)、图书馆系统(借阅记录、馆藏信息)、一卡通系统(消费数据、门禁记录)等。 接入方式:提供数据库直连(MySQL、SQL Server)、文件导入(CSV、Excel、JSON)、API 接口调用等多种方式,支持实时同步与定时批量同步。 数据标准化与治理 建立校园数据标准体系:统一数据格式(如日期格式、学号编码规则)、定义核心数据元(如 “学生” 包含学号、姓名、专业等必选字段)、规范代码集(如性别代码 “1 - 男,2 - 女”)。 数据清洗:自动检测并处理缺失值、重复值、异常值(如成绩 > 100 分),通过规则引擎实现数据校验(如 “学生年龄需在 16-30 岁之间”)。 元数据管理:记录数据来源、格式、更新频率、负责人等信息,生成数据血缘图谱,追踪数据从产生到应用的全生命周期。 二、数据共享与交换核心功能 分布式数据存储 基于 Hadoop HDFS 实现海量数据存储:结构化数据(成绩、消费记录)存入 HBase,非结构化数据(文档、图片、视频)直接存储于 HDFS,日志类数据通过 Flume 采集至 HDFS。 支持数据分片与副本机制,确保数据高可用(默认 3 副本存储),满足校园 PB 级数据存储需求。 数据交换引擎 构建点对点数据交换通道:各部门系统可通过交换引擎向平台上传数据或申请获取授权数据,支持同步 / 异步交换模式。 交换流程管理:定义数据交换规则(如 “学工系统每日向平台同步新增学生信息”),记录交换日志(成功 / 失败状态、数据量),失败时自动重试。 数据脱敏:对敏感数据(如身份证号、银行卡号)在交换过程中进行脱敏处理(如显示 “110********5678”),兼顾共享与隐私保护。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值